Hi,
I'd like to index some data in a modular way using the new Java Client API and I don't see how to achieve this by passing a Java object. The issue is that this object needs to contain all fields and that doesn't make it modular. I'd like that several modules/component contribute fields dynamically.
This is what I have ATM:
Ping ping = new Ping();
provideData(ping);
IndexResponse response = client.index(builder -> builder
.index(ElasticsearchClientManager.INDEX)
.document(ping)
);
In the past, I was writing the following where each module was contributing some JSON part:
Index index = new Index.Builder(constructIndexJSON())
.index(JestClientManager.INDEX)
.type(JestClientManager.TYPE)
.build();
JestResult result = client.execute(index);
...
private String constructIndexJSON()
{
Map<String, Object> jsonMap = new HashMap<>();
for (PingDataProvider pingDataProvider : this.pingDataProviderProvider.get()) {
jsonMap.putAll(pingDataProvider.provideData());
}
return JSONObject.fromObject(jsonMap).toString();
}
Any idea?
Thanks a lot!