Skip to content

Add a {{#toJson}} function (that accepts map as an argument) to the the elasticsearch mustache integration #18898

@rvalenciano

Description

@rvalenciano

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

Describe the feature:

I'm having the exact same issue of this thread: Basically watcher ctx is giving me a java.util.HashMap object and I need a json object. Today, is only possible to do a tedious manual construction of it.

I opened a closed issue here:

#18807

After recommendation, I moved the discussion to the official elasticsearch discussion forum:

There, I received feedback from Alexander Reelsen as I quote:

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.

And

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.

So, in my client parsing this result, I created some regex in ruby where I'm able to parse from the topbeat java.util.HashMap sent in payload.hits to json. But it would be nice if we can add this feature into the elasticsearch mustache integration as Alexander says.

I'm willing to contribute to this as a developer, if needed. Just not quite sure how to start.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions