# Referring to fields with a "-" character in Painless

**URL:** <https://discuss.elastic.co/t/referring-to-fields-with-a-character-in-painless/180468>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [May 10, 2019, 2:14am UTC](https://discuss.elastic.co/t/referring-to-fields-with-a-character-in-painless/180468 "2019-05-10T02:14:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vkandiva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vkandiva/32/42845_2.png) [@vkandiva](https://discuss.elastic.co/u/vkandiva)\
**Post date:** [May 10, 2019, 2:14am UTC](https://discuss.elastic.co/t/referring-to-fields-with-a-character-in-painless/180468/1 "2019-05-10T02:14:29Z")

</div>

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."

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [May 10, 2019, 6:53am UTC](https://discuss.elastic.co/t/referring-to-fields-with-a-character-in-painless/180468/2 "2019-05-10T06:53:59Z")

</div>

`-` 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:

```auto
"ctx._source['keyid'] = ctx._source['inbound-value-id'];"

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 7, 2019, 6:54am UTC](https://discuss.elastic.co/t/referring-to-fields-with-a-character-in-painless/180468/3 "2019-06-07T06:54:18Z")

</div>

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