Package org.elasticsearch.client
Class RestClientBuilder
java.lang.Object
org.elasticsearch.client.RestClientBuilder
Helps creating a new
RestClient
. Allows to set the most common http client configuration options when internally
creating the underlying HttpAsyncClient
. Also allows to provide an externally created
HttpAsyncClient
in case additional customization is needed.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Callback used to customize theCloseableHttpClient
instance used by aRestClient
instance.static interface
Callback used the defaultRequestConfig
being set to theCloseableHttpClient
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final String
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Creates a newRestClient
based on the provided configuration.static String
cleanPathPrefix
(String pathPrefix) setCompressionEnabled
(boolean compressionEnabled) Whether the REST client should compress requests using gzip content encoding and add the "Accept-Encoding: gzip" header to receive compressed responses.setDefaultHeaders
(org.apache.http.Header[] defaultHeaders) Sets the default request headers, which will be sent along with each request.setFailureListener
(RestClient.FailureListener failureListener) Sets theRestClient.FailureListener
to be notified for each request failuresetHttpClientConfigCallback
(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback) Sets theRestClientBuilder.HttpClientConfigCallback
to be used to customize http client configurationsetMetaHeaderEnabled
(boolean metadataEnabled) Whether to send aX-Elastic-Client-Meta
header that describes the runtime environment.setNodeSelector
(NodeSelector nodeSelector) Sets theNodeSelector
to be used for all requests.setPathPrefix
(String pathPrefix) Sets the path's prefix for every request used by the http client.setRequestConfigCallback
(RestClientBuilder.RequestConfigCallback requestConfigCallback) Sets theRestClientBuilder.RequestConfigCallback
to be used to customize http client configurationsetStrictDeprecationMode
(boolean strictDeprecationMode) Whether the REST client should return any response containing at least one warning header as a failure.
-
Field Details
-
DEFAULT_CONNECT_TIMEOUT_MILLIS
public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS- See Also:
-
DEFAULT_SOCKET_TIMEOUT_MILLIS
public static final int DEFAULT_SOCKET_TIMEOUT_MILLIS- See Also:
-
DEFAULT_MAX_CONN_PER_ROUTE
public static final int DEFAULT_MAX_CONN_PER_ROUTE- See Also:
-
DEFAULT_MAX_CONN_TOTAL
public static final int DEFAULT_MAX_CONN_TOTAL- See Also:
-
VERSION
-
-
Method Details
-
setDefaultHeaders
Sets the default request headers, which will be sent along with each request.Request-time headers will always overwrite any default headers.
- Throws:
NullPointerException
- ifdefaultHeaders
or any header isnull
.
-
setFailureListener
Sets theRestClient.FailureListener
to be notified for each request failure- Throws:
NullPointerException
- iffailureListener
isnull
.
-
setHttpClientConfigCallback
public RestClientBuilder setHttpClientConfigCallback(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback) Sets theRestClientBuilder.HttpClientConfigCallback
to be used to customize http client configuration- Throws:
NullPointerException
- ifhttpClientConfigCallback
isnull
.
-
setRequestConfigCallback
public RestClientBuilder setRequestConfigCallback(RestClientBuilder.RequestConfigCallback requestConfigCallback) Sets theRestClientBuilder.RequestConfigCallback
to be used to customize http client configuration- Throws:
NullPointerException
- ifrequestConfigCallback
isnull
.
-
setPathPrefix
Sets the path's prefix for every request used by the http client.For example, if this is set to "/my/path", then any client request will become
"/my/path/" + endpoint
.In essence, every request's
endpoint
is prefixed by thispathPrefix
. The path prefix is useful for when Elasticsearch is behind a proxy that provides a base path or a proxy that requires all paths to start with '/'; it is not intended for other purposes and it should not be supplied in other scenarios.- Throws:
NullPointerException
- ifpathPrefix
isnull
.IllegalArgumentException
- ifpathPrefix
is empty, or ends with more than one '/'.
-
cleanPathPrefix
-
setNodeSelector
Sets theNodeSelector
to be used for all requests.- Throws:
NullPointerException
- if the provided nodeSelector is null
-
setStrictDeprecationMode
Whether the REST client should return any response containing at least one warning header as a failure. -
setCompressionEnabled
Whether the REST client should compress requests using gzip content encoding and add the "Accept-Encoding: gzip" header to receive compressed responses. -
setMetaHeaderEnabled
Whether to send aX-Elastic-Client-Meta
header that describes the runtime environment. It contains information that is similar to what could be found inUser-Agent
. Using a separate header allows applications to useUser-Agent
for their own needs, e.g. to identify application version or other environment information. Defaults totrue
. -
build
Creates a newRestClient
based on the provided configuration.
-