elasticsearch-java icon indicating copy to clipboard operation
elasticsearch-java copied to clipboard

Return a CompletableFuture from BulkIngester.flush method

Open aidin36 opened this issue 1 year ago • 5 comments
trafficstars

The Issue

In one case in our production app, we want to flush the bulk operations and make them immediately available for search. So, we do a flush on our BulkIngester instance, then we do a client.indices().refresh(). However, because the flush operation is asynchronous, most of the time before all the operations flush, the refresh gets called. So, some of the changes aren't immediately available for search.

The Solution

I returned a CompletableFuture from the flush method, so the user can wait for the flush to finish if required.

Documents

Sorry, I couldn't find where's the document for the flush method so I could update it. If you point me to it, I can update the return type there.

gradlew check

There are nine failing tests. But they were failing before my changes too.

aidin36 avatar May 10 '24 01:05 aidin36

💚 CLA has been signed

Hello! Before changing the code, have you tried the refresh option in the globalSettings of the BulkIngester? Setting it to true would refresh after every BulkRequest , making the new data available to search.

l-trotta avatar May 31 '24 15:05 l-trotta

Hi (: Thanks for the suggestion. Ideally, I don't want to refresh on all the bulk requests and let Elastic Search decide when is the right time to do so. We only need it in a specific case.

Besides my use case, I believe it's a good idea to return a Future from all the async methods and allow the client to know what happened to the result of the call.

aidin36 avatar Jun 25 '24 01:06 aidin36

Hi,

I also think that this change is really necessary as it is resolving also our use case as well. For us it is important that flush will wait untill afterBulk will be called, so with this change we would simply wait for flush to finish.

sebastianrtb avatar Jul 25 '24 11:07 sebastianrtb

I think this relates to #703

fabriziofortino avatar Aug 20 '24 10:08 fabriziofortino