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
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback used to customize theCloseableHttpClientinstance used by aRestClientinstance.static interfaceCallback used the defaultRequestConfigbeing set to theCloseableHttpClient -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final String -
Method Summary
Modifier and TypeMethodDescriptionbuild()Creates a newRestClientbased on the provided configuration.static StringcleanPathPrefix(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.FailureListenerto be notified for each request failuresetHttpClientConfigCallback(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback) Sets theRestClientBuilder.HttpClientConfigCallbackto be used to customize http client configurationsetMetaHeaderEnabled(boolean metadataEnabled) Whether to send aX-Elastic-Client-Metaheader that describes the runtime environment.setNodeSelector(NodeSelector nodeSelector) Sets theNodeSelectorto 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.RequestConfigCallbackto 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- ifdefaultHeadersor any header isnull.
-
setFailureListener
Sets theRestClient.FailureListenerto be notified for each request failure- Throws:
NullPointerException- iffailureListenerisnull.
-
setHttpClientConfigCallback
public RestClientBuilder setHttpClientConfigCallback(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback) Sets theRestClientBuilder.HttpClientConfigCallbackto be used to customize http client configuration- Throws:
NullPointerException- ifhttpClientConfigCallbackisnull.
-
setRequestConfigCallback
public RestClientBuilder setRequestConfigCallback(RestClientBuilder.RequestConfigCallback requestConfigCallback) Sets theRestClientBuilder.RequestConfigCallbackto be used to customize http client configuration- Throws:
NullPointerException- ifrequestConfigCallbackisnull.
-
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
endpointis 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- ifpathPrefixisnull.IllegalArgumentException- ifpathPrefixis empty, or ends with more than one '/'.
-
cleanPathPrefix
-
setNodeSelector
Sets theNodeSelectorto 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-Metaheader 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-Agentfor their own needs, e.g. to identify application version or other environment information. Defaults totrue. -
build
Creates a newRestClientbased on the provided configuration.
-