lkatiforis
lkatiforis

Reputation: 6255

Elasticsearch Script - Unexpected characters

I am trying to update a doc using painless scripts. My document contain fields like "a4ayc/8" (the field name contains the character /).

Document sample:

   {
        "_index" : "user_profile",
        "_type" : "_doc",
        "_id" : "SQ9/X1iKV7DDJXJLLMAvyt",
        "_score" : 1.0,
        "_source" : {
          "TgdAhWI" : "text",
          "a4ayc/8" : 1,
          "SyJ3d9Q" : true,
          "qBC0wbU" : "2021-05-25T14:22:40.804Z"
        }
      }

Executing the following script i get an exception for the "a4ayc/8" field:

[type=illegal_argument_exception, reason=invalid assignment: cannot assign a value to division operation [/]]

Script:

{
       "script":{
          "source":"ctx._source.TgdAhWI = params.param1; ctx._source.qBC0wbU = params.param2; ctx._source.a4ayc/8 = params.param3; ctx._source.SyJ3d9Q = params.param4; ",
          "lang":"painless",
          "params":{
             "param3":1,
             "param4":true,
             "param1":"text",
             "param2":"2021-05-25T14:22:40.804Z"
          }
       },
       "upsert":{
          "TgdAhWI":"text",
          "a4ayc/8":1,
          "SyJ3d9Q":true,
          "qBC0wbU":"2021-05-25T14:22:40.804Z"
       }
    }

Is there a workaround to this?

Upvotes: 0

Views: 973

Answers (1)

Val
Val

Reputation: 217464

Yes, you simply need to reference the field differently, like this:

ctx._source['a4ayc/8'] = params.param3

And it would be the same thing if your field name starts with a number because it would not be a valid Painless identifier, e.g.

ctx._source['4a4ayc8'] = params.param3

Upvotes: 1

Related Questions