# Working with fields containing underline in painless scripts

**URL:** https://discuss.elastic.co/t/working-with-fields-containing-underline-in-painless-scripts/118646
**Category:** Elasticsearch
**Created:** [February 6, 2018, 12:48pm UTC](https://discuss.elastic.co/t/working-with-fields-containing-underline-in-painless-scripts/118646 "2018-02-06T12:48:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mh20](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mh20](https://discuss.elastic.co/u/mh20)
#### Post date: [February 6, 2018, 12:48pm UTC](https://discuss.elastic.co/t/working-with-fields-containing-underline-in-painless-scripts/118646/1 "2018-02-06T12:48:58Z")

</div>

Hi, I am writing a painless script for removing values from arrays as described in [https://discuss.elastic.co/t/removing-elements-from-an-array-in-a-document/10156](https://discuss.elastic.co/t/removing-elements-from-an-array-in-a-document/10156) and [https://stackoverflow.com/questions/45980054/how-to-remove-arraylist-value-in-elastic-search-using-curl](https://stackoverflow.com/questions/45980054/how-to-remove-arraylist-value-in-elastic-search-using-curl) but my field names contain underline which cause error. For example first script work fine:  
{  
"script": {  
"lang": "painless",  
"inline": "ctx.\_source.my\_field.removeAll(Collections.singleton('valueToRemove'))"  
}  
}  
But second script:  
{  
"script":  
{  
"inline": "ctx.\_source.11\_my\_field.removeAll(Collections.singleton('valueToRemove'))"  
},  
"query":  
{  
"match\_all": {}  
}  
}  
caused this error:  
{  
"error": {  
"root\_cause": [  
{  
"type": "script\_exception",  
"reason": "compile error",  
"script\_stack": [  
"ctx.\_source.11\_my\_field.removeAll(Colle ...",  
" ^---- HERE"  
],  
"script": "ctx.\_source.11\_my\_field.removeAll(Collections.singleton('new\_name2'))",  
"lang": "painless"  
}  
],  
"type": "script\_exception",  
"reason": "compile error",  
"script\_stack": [  
"ctx.\_source.11\_my\_field.removeAll(Colle ...",  
" ^---- HERE"  
],  
"script": "ctx.\_source.11\_my\_field.removeAll(Collections.singleton('new\_name2'))",  
"lang": "painless",  
"caused\_by": {  
"type": "illegal\_argument\_exception",  
"reason": "unexpected token ['\_my\_field'] was expecting one of [{, ';'}]."  
}  
},  
"status": 500  
}

What should I do? How can I write this script for fields that start with number and contain underline?

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [February 6, 2018, 12:51pm UTC](https://discuss.elastic.co/t/working-with-fields-containing-underline-in-painless-scripts/118646/2 "2018-02-06T12:51:00Z")

</div>

Can you try this way?

```
ctx._source['11_my_field'].removeAll(Collections.singleton('new_name2'))
```

---

<div class="post-metadata">

### Author: ![mh20](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mh20](https://discuss.elastic.co/u/mh20)
#### Post date: [February 6, 2018, 12:56pm UTC](https://discuss.elastic.co/t/working-with-fields-containing-underline-in-painless-scripts/118646/3 "2018-02-06T12:56:05Z")

</div>

Thanks, It worked!

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [February 6, 2018, 12:57pm UTC](https://discuss.elastic.co/t/working-with-fields-containing-underline-in-painless-scripts/118646/4 "2018-02-06T12:57:51Z")

</div>

Awesome, glad we figured it out!

---

<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: [March 6, 2018, 12:58pm UTC](https://discuss.elastic.co/t/working-with-fields-containing-underline-in-painless-scripts/118646/5 "2018-03-06T12:58:25Z")

</div>

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