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?
It is the field called "name" in your example that I am trying to avoid. Is there a way that I can use the field "foo" in your example as the field name (basically telling XcontentBuilder, here is a JSON object to insert and you should take the existing field name from that) without having to specify another one.
Also, XcontentParser only seems to return me the first object in an array. How can I get to the other values, when I supply an array of objects?
I got this working now! Thank you. I hadn't realised that it was possible to just call jsonBuilder.field(name) and then to do the copyCurrrentStructure(exampleString) immediately after. This solved it for me!
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.