Referring to fields with a "-" character in Painless

So one of our legacy indexes has a field with a name "inbound-value-id". I was using the Update by Query API to update some field using Painless scripting and it was working well but just for this field with special characters I am not sure how to refer it in Painless.

Below is a the script:
POST: /index_name/_update_by_query?pretty=true
{
"script": {
"source": "ctx._source.keyid = ctx._source.inbound-value-id;"
}
}

which gives me the following error:

  • "type": "illegal_argument_exception",
  • "reason": "Variable [value] is not defined."

- isn't a valid character within an identifer (ie a variable name). While maps in painless (like _source is) support accessing keys through dot notation, the safer way to access keys is with brackets:

"ctx._source['keyid'] = ctx._source['inbound-value-id'];"
1 Like

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