Class RestHighLevelClient

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class RestHighLevelClient
    extends java.lang.Object
    implements java.io.Closeable
    High level REST client that wraps an instance of the low level RestClient and allows to build requests and read responses. The RestClient instance is internally built based on the provided RestClientBuilder and it gets closed automatically when closing the RestHighLevelClient instance that wraps it.

    In case an already existing instance of a low-level REST client needs to be provided, this class can be subclassed and the RestHighLevelClient(RestClient, CheckedConsumer, List) constructor can be used.

    This class can also be sub-classed to expose additional client methods that make use of endpoints added to Elasticsearch through plugins, or to add support for custom response sections, again added to Elasticsearch through plugins.

    The majority of the methods in this class come in two flavors, a blocking and an asynchronous version (e.g. search(SearchRequest, RequestOptions) and searchAsync(SearchRequest, RequestOptions, ActionListener), where the later takes an implementation of an ActionListener as an argument that needs to implement methods that handle successful responses and failure scenarios. Most of the blocking calls can throw an IOException or an unchecked ElasticsearchException in the following cases:

    • an IOException is usually thrown in case of failing to parse the REST response in the high-level REST client, the request times out or similar cases where there is no response coming back from the Elasticsearch server
    • an ElasticsearchException is usually thrown in case where the server returns a 4xx or 5xx error code. The high-level client then tries to parse the response body error details into a generic ElasticsearchException and suppresses the original ResponseException