I have data flowing into a document from two sources. One is text which needs to be converted to JSON. Simple to add it using:
jsonBuilder.field(name, value);
The other source has data that is already formatted as JSON.
String nestedExample = "{\"Details\": [ {\"Login\":\"ABC\", \"DateTime\": 123213113},{\"Login\":\"BCD\", \"DateTime\": 123213213}, {\"Login\":\"EFG\", \"DateTime\": 123213413}]}";
I found that I could use jsonBuilder,rawField to insert prebuilt JSON, however it always wants a field name.If I use:
InputStream jsonStream = new ByteArrayInputStream(nestedExample.getBytes());
jsonBuilder.rawField(name, jsonStream);
It creates an additional field name which creates an additional layer of nesting to my data structure.
I cannot find a way to insert this raw data that doesnt require me to specify a field name, which creates an additional layer of nesting that I do not want.
I have also tried using XContentParser and then copyCurrentStructure, but that also needs a field name and again creates an additioanl layer of nesting.
I'm sure this is really simple, but how can I insert raw JSON into a document field using XContentBuilder?
Thanks!