Search code examples
javaelasticsearchelasticsearch-2.0elasticsearch-java-api

Executing a UpdateByQueryRequest in Elasticsearch Java client


I want to run an update-by-query call on Elasticsearch. I wrote the code to execute as follows and it works,

UpdateByQueryRequestBuilder builder = buildUpdateByQueryRequestBuilder();
builder.get();

However, during the code review someone told me to, instead of calling get() on the builder to use UpdateByQueryRequest class by invoking builder.request() which sorta makes sense.

But the issue is, I don't know how to execute a UpdateByQueryRequest. I looked at the online documentation but there doesn't seem to be any documentation on it.

So is UpdateByQueryRequestBuilder#get() the way to go or could an UpdateByQueryRequest be actually be invoked?

Thanks in advance.


Solution

  • invoke builder.get() directly, this is a block execute, you can use execute with ActionListener async execute.

    maybe you can do it like:

    builder.execute(new ActionListner<BulkIndexByScrollResponse> {
       void onResponse(Response response) {
       // do something
       }
       void onFailure(Exception e) {
       // do something
       }
    }