Geting JSON from ctx.payload.hits in a webhook action that Ruby consumes

Hi,

Using elasticsearch and watcher, I'm having the same issue as here:

However, using the proposed solution is not working, groovy.json.JSONOutput is not supported anymore. I opened an issue in the elastic repo.

There you can read deeply about the situation. Summarizing, watcher ctx.payload.hits is giving me a java.util.HashMap object and I need a json object.

Any other possible way to retrieve a json instead of a java.util.HashMap response from watcher ctx? Or do I have to program using groovy core a parser from HashMap to json?

I'm using

Elasticsearch version: 2.3

JVM version: openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

OS version: centOS 7

Hey,

indeed I dont see a clean way that this is possible at the moment, without tedious manual construction inside of a string. Maybe a mustache function like {{#toJson}} (that accepts map as an argument) could help a lot here - but I am not sure if this is how mustache works, as I would expect it to only be able to handle strings - need to check it out.

--Alex

Hi!

Thanks for the response. I manage using some regex in ruby to parse it down. It would be nice to contribute to the community, but not sure how to proceed.

Best

Hey,

Taking a look at the elasticsearch mustache integration and the possibility to add a JSON function might make sense here. This could be reused in watcher then.

Happy to help with first steps!

--Alex

@Randall_Valenciano_F Would you mind sharing the regex which you used to parse in ruby ? I'm stuck right here.

Hey,

Just FYI: In Elasticsearch 2.4 and above we added a toJson mustache directive. See the PR https://github.com/elastic/elasticsearch/pull/19153 and the documentation of that one in particular https://github.com/elastic/elasticsearch/pull/19153/files#diff-b99a30a3f37550a69a2508b3a3e120a6R226

--Alex