JSON attributes are treated like normal strings and are escaped by the sink. For example, if the body or a header contains the following value:
It will be added like this in Elasticsearch:
We end up with a plain string instead of a valid JSON field.
I think I found how to fix this bug. The source of the problem is caused by the way a "complex field" is added. The ES XContent classes are used to parse the data in the detected format, but then, instead of adding the parsed data, the string() method is called and it converts it back to a string that is the same as the initial data! Here is the current code with added comments:
If we really want to take advantage of the XContent classes, we have to add the parsed data to the builder. To do this, it is as simply as:
I tried this and it works as expected.