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

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 =;
       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": [
"... ...",
" ^---- HERE"

caused_by": {
"type": "illegal_argument_exception",
"reason": "Variable [pcm] is not defined."


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

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


Thanks Alexander , it worked :smiley:

1 Like

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