I want to create a watch that generates an action for a certain event, but I want to format the output using a mustache template.
In the output I want to be able to say when each event happened, e.g.
{{#ctx.payload.hits.hits}}
At {{_source.@timestamp}} this happened.
{{/ctx.payload.hits.hits}}
I am using an online mustache template tester to help write the template, but this tester doesn't seem to be able to access fields that start with an @.
Will this work in elasticsearch? If not, how would I get the field value since its key starts with @
From what I can tell Mustache won't work with fields that start with an @ sign. (Probably because Javascript identifiers can't start with an @). You could set up a scripted field timestamp that just returns the timestamp. Or you could change your documents so that the timestamp field doesn't start with an @ sign.
That is odd that the tstamp comes as an array. Sounds like maybe a watcher bug? Pretty sure that scripted fields don't work like that in other contexts. Glad that you got it working.
[2018-08-07T08:34:02,287][INFO ][o.e.x.w.a.l.ExecutableLoggingAction] [DWc9wWT] At 123 this happened.
so maybe the issue is somewhere else? If you share your whole watch and the output of the execute watch API in a gist, that would make it easier to help.
Thank you @spinscale, this worked for me as well. I had not tried accessing @timestamp from within the watch, I had only tried it with the javascript version of mustache, which is what seems to have the problem accessing fields with @ in them.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.