I use an XContentBuilder object to build a Json string.
XContentBuilder builder = XContentFactory.jsonBuilder().startObject()
.field(Constants.OSM_ID, doc.getOsmId())
.field(Constants.OSM_TYPE, doc.getOsmType())
.field(Constants.OSM_KEY, doc.getTagKey())
.field(Constants.OSM_VALUE, doc.getTagValue())
.field(Constants.IMPORTANCE, doc.getImportance());
Now I would like to System.out the resulting Json String. How can I do this?
since elastic client v6.3
import org.elasticsearch.common.Strings;
String json = Strings.toString(builder);
see elastic docs
Finish building:
String s = builder.string();
System.out.println(s);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With