Performing requests

edit

Once the RestClient has been created, requests can be sent by calling one of the available performRequest or performRequestAsync method variants. The performRequest methods are synchronous and they return the Response directly, meaning that the client will block and wait for a response to be returned. The performRequestAsync variants, which return void and accept an extra ResponseListener as an argument, are executed asynchronously. The provided listener will be notified upon completion or failure.

// Synchronous variants
Response performRequest(String method, String endpoint,
                        Header... headers)
    throws IOException;

Response performRequest(String method, String endpoint,
                        Map<String, String> params, Header... headers)
    throws IOException;

Response performRequest(String method, String endpoint,
                        Map<String, String> params,
                        HttpEntity entity,
                        Header... headers)
    throws IOException;

Response performRequest(String method, String endpoint,
                        Map<String, String> params,
                        HttpEntity entity,
                        HttpAsyncResponseConsumerFactory responseConsumerFactory,
                        Header... headers)
    throws IOException;

// Asynchronous variants
void performRequestAsync(String method, String endpoint,
                         ResponseListener responseListener,
                         Header... headers);

void performRequestAsync(String method, String endpoint,
                         Map<String, String> params,
                         ResponseListener responseListener,
                         Header... headers);

void performRequestAsync(String method, String endpoint,
                         Map<String, String> params,
                         HttpEntity entity,
                         ResponseListener responseListener,
                         Header... headers);

void performRequestAsync(String method, String endpoint,
                         Map<String, String> params,
                         HttpEntity entity,
                         HttpAsyncResponseConsumerFactory responseConsumerFactory,
                         ResponseListener responseListener,
                         Header... headers);

Request Arguments

edit

The following are the arguments accepted by the different methods:

method
the http method or verb
endpoint
the request path, which identifies the Elasticsearch API to call (e.g. /_cluster/health)
params
the optional parameters to be sent as querystring parameters
entity
the optional request body enclosed in an org.apache.http.HttpEntity object
responseConsumerFactory
the optional factory that is used to create an org.apache.http.nio.protocol.HttpAsyncResponseConsumer callback instance per request attempt. Controls how the response body gets streamed from a non-blocking HTTP connection on the client side. When not provided, the default implementation is used which buffers the whole response body in heap memory, up to 100 MB
responseListener
the listener to be notified upon asynchronous request success or failure
headers
optional request headers