How to build Json document In Elasticsearch 8 API client , as In older Client APIs its possible to build using XContentBuilder like
XContentBuilder builder = jsonBuilder()
.startObject()
.field("firstName", "jhon")
.field("lastname", "doe")
.field("message", "trying out Elasticsearch")
.endObject()```
But now in ES8 Java API Client i do not see any way to build Json doc, for example if i want to insert a "Student" into "School" index , then possible ways are
1- using direct bean as document
esClient.index(i -> i
.index("school")
.id(product.getId())
.document(student)
2- using pre builded json as string (no way to build explicitly)
Reader input = new StringReader(
"{'@timestamp': '2022-04-08T13:55:32Z', 'firstName': 'jhone', 'lastName': 'doe'}"
.replace('\'', '"'));
IndexRequest<JsonData> request = IndexRequest.of(i -> i
.index("school")
.withJson(input)
);
3- using JsonData class
JsonpMapper jsonpMapper = esClient.jsonpMapper();
JsonData jsonData = JsonData.of(student , jsonpMapper);
esClient.index(i -> i
.index("school")
.id(product.getId())
.document(jsonData)
so is there any way to build Json using Java API Client and input as doc to index