IndexRequestBuilder.execute().actionGet() vs IndexRequestBuilder.get()

Can someone explain the different of this two APIs (actionGet and get).

I know the IndexRequestBuilder.execute().actionGet() is a combination of an async call execute() and actionGet() waits for its result with an additional parameter timeout. How about the behavior of IndexRequestBuilder.get(). Is this a synchronized call?

The other thing would like to clarify is the ElasticSearch on-line documents says Java client suppose to be async no matter which thread model used. Is this a valid statement? If you look at the IndexRequestBuilder.execute().actionGet(), the client is blocked and wait for the response by the call actionGet(). This should be a synchronized call from client perspective even ElasticSearch handle the request in an async approach


get() is just .execute().actionGet().

execute() returns a ListenableActionFuture which is just like a normal Future with some decorations to make working with it a bit easier. It is an async thing.

actionGet() will block the current thread until the request is done. The API is still asynchronous but you are using it synchronously because that is easier. If you want to use the API asynchronously you can call execute(ActionListener<Response> listener) with your own listener.

1 Like