I'm relatively new to ElasticSearch and I've noticed when you start elasticsearch Java Client, it starts a large number of threads (~50).
I was trying to leverage this, buy couldn't find a way to make an async write (index) to ES.
The official API suggestion is to use:
IndexResponse response = client.prepareIndex(indexName, documentName)
.setSource(mapper.writeValueAsString(data))
.get();
Even though I have this running on a new thread it is still blocking as it waits for the response, containing the new created ID and more.
Is it possible to write to ES in an asynchronous manner, without having to create another 50 local threads to match the 50 internal ones of ES?
If anyone stumbles across this, the solution was to use .execute(), which returns a ListenableActionFuture<Response>.
e.g.
client.prepareIndex(indexName, documentName)
.setSource(mapper.writeValueAsString(data))
.execute();
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