Painless 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 any way to update field "a4ayc/8" using scripts?

Have a look at literals in painless
I think this is something to do because the / is a special character

@debrt is correct.

If you need to update a field with special characters, you cannot use the shortcut syntax, ctx._source.a4ayc/8, and instead should use the map syntax, ctx._source['a4ayc/8'].

In general, we recommend the map syntax for this reason. The shortcut syntax is best for quick one-offs.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.