# Is there a way to escape hyphen (-) in painless

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-escape-hyphen-in-painless/194603>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [August 9, 2019, 11:46am UTC](https://discuss.elastic.co/t/is-there-a-way-to-escape-hyphen-in-painless/194603 "2019-08-09T11:46:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![liju87](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/liju87/32/122763_2.png) [@liju87](https://discuss.elastic.co/u/liju87)\
**Post date:** [August 9, 2019, 11:46am UTC](https://discuss.elastic.co/t/is-there-a-way-to-escape-hyphen-in-painless/194603/1 "2019-08-09T11:46:11Z")

</div>

I'm trying to create a watcher to fetch the stats data for an index and writing it back to a new index  
I have noticed when I'm using an index with name pcm the transform works but when I'm using a Index with name for example vmstat-pcm-test its failing ,  
Is there way we can escape hyphen (-) in painless ?

Please find the Transform and Error message below.

**Transform** -  
"transform": {  
"script": {  
"source": """

```
       def store_size_in_bytes = ctx.payload.indices.vmstat-pcm-test.primaries.store.size_in_bytes;
       
       def result_list = [];
       def data = ['@timestamp':ctx.trigger.triggered_time,'Store_Size' : store_size_in_bytes];
       result_list.add ( data );
        
       return ['_doc': result_list];
     """,
     "lang": "painless"
   }
 }

```

**Error message** -

"type": "script\_exception",  
"reason": "compile error",  
"script\_stack": [  
"... x.payload.indices.vmstat-pcm-test.primaries.store. ...",  
" ^---- HERE"  
],

caused\_by": {  
"type": "illegal\_argument\_exception",  
"reason": "Variable [pcm] is not defined."  
}

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [August 12, 2019, 8:33am UTC](https://discuss.elastic.co/t/is-there-a-way-to-escape-hyphen-in-painless/194603/2 "2019-08-12T08:33:49Z")

</div>

Hey,

try putting that name in brackets (`['']`) like this `ctx.payload.indices['vmstat-pcm-test'].primaries.store.size_in_bytes`.

You can also use brackets for every field if you want to, but in general I find the dot notation more readable.

--Alex

---

<div class="post-metadata">

**Author:** ![liju87](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/liju87/32/122763_2.png) [@liju87](https://discuss.elastic.co/u/liju87)\
**Post date:** [August 12, 2019, 9:12am UTC](https://discuss.elastic.co/t/is-there-a-way-to-escape-hyphen-in-painless/194603/3 "2019-08-12T09:12:09Z")

</div>

Thanks Alexander , it worked 😃

---

<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:** [September 9, 2019, 9:12am UTC](https://discuss.elastic.co/t/is-there-a-way-to-escape-hyphen-in-painless/194603/4 "2019-09-09T09:12:19Z")

</div>

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