Class RestClientBuilder

java.lang.Object
org.elasticsearch.client.RestClientBuilder

public final class RestClientBuilder extends Object
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.
  • Field Details

    • DEFAULT_CONNECT_TIMEOUT_MILLIS

      public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS
      See Also:
      Constant Field Values
    • DEFAULT_SOCKET_TIMEOUT_MILLIS

      public static final int DEFAULT_SOCKET_TIMEOUT_MILLIS
      See Also:
      Constant Field Values
    • DEFAULT_MAX_CONN_PER_ROUTE

      public static final int DEFAULT_MAX_CONN_PER_ROUTE
      See Also:
      Constant Field Values
    • DEFAULT_MAX_CONN_TOTAL

      public static final int DEFAULT_MAX_CONN_TOTAL
      See Also:
      Constant Field Values
  • Method Details

    • setDefaultHeaders

      public RestClientBuilder setDefaultHeaders(org.apache.http.Header[] defaultHeaders)
      Sets the default request headers, which will be sent along with each request.

      Request-time headers will always overwrite any default headers.

      Throws:
      NullPointerException - if defaultHeaders or any header is null.
    • setFailureListener

      public RestClientBuilder setFailureListener(RestClient.FailureListener failureListener)
      Sets the RestClient.FailureListener to be notified for each request failure
      Throws:
      NullPointerException - if failureListener is null.
    • setHttpClientConfigCallback

      public RestClientBuilder setHttpClientConfigCallback(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback)
      Sets the RestClientBuilder.HttpClientConfigCallback to be used to customize http client configuration
      Throws:
      NullPointerException - if httpClientConfigCallback is null.
    • setRequestConfigCallback

      public RestClientBuilder setRequestConfigCallback(RestClientBuilder.RequestConfigCallback requestConfigCallback)
      Sets the RestClientBuilder.RequestConfigCallback to be used to customize http client configuration
      Throws:
      NullPointerException - if requestConfigCallback is null.
    • setPathPrefix

      public RestClientBuilder setPathPrefix(String pathPrefix)
      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 this pathPrefix. 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 - if pathPrefix is null.
      IllegalArgumentException - if pathPrefix is empty, or ends with more than one '/'.
    • cleanPathPrefix

      public static String cleanPathPrefix(String pathPrefix)
    • setNodeSelector

      public RestClientBuilder setNodeSelector(NodeSelector nodeSelector)
      Sets the NodeSelector to be used for all requests.
      Throws:
      NullPointerException - if the provided nodeSelector is null
    • setStrictDeprecationMode

      public RestClientBuilder setStrictDeprecationMode(boolean strictDeprecationMode)
      Whether the REST client should return any response containing at least one warning header as a failure.
    • setCompressionEnabled

      public RestClientBuilder 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.
    • setMetaHeaderEnabled

      public RestClientBuilder setMetaHeaderEnabled(boolean metadataEnabled)
      Whether to send a X-Elastic-Client-Meta header that describes the runtime environment. It contains information that is similar to what could be found in User-Agent. Using a separate header allows applications to use User-Agent for their own needs, e.g. to identify application version or other environment information. Defaults to true.
    • build

      public RestClient build()
      Creates a new RestClient based on the provided configuration.