public class RestHighLevelClient
extends java.lang.Object
implements java.io.Closeable
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.Modifier | Constructor and Description |
---|---|
|
RestHighLevelClient(RestClientBuilder restClientBuilder)
Creates a
RestHighLevelClient given the low level RestClientBuilder that allows to build the
RestClient to be used to perform requests. |
protected |
RestHighLevelClient(RestClientBuilder restClientBuilder,
java.util.List<NamedXContentRegistry.Entry> namedXContentEntries)
Creates a
RestHighLevelClient given the low level RestClientBuilder that allows to build the
RestClient to be used to perform requests and parsers for custom response sections added to Elasticsearch through plugins. |
protected |
RestHighLevelClient(RestClient restClient,
CheckedConsumer<RestClient,java.io.IOException> doClose,
java.util.List<NamedXContentRegistry.Entry> namedXContentEntries)
Creates a
RestHighLevelClient given the low level RestClient that it should use to perform requests and
a list of entries that allow to parse custom response sections added to Elasticsearch through plugins. |
Modifier and Type | Method and Description |
---|---|
BulkResponse |
bulk(BulkRequest bulkRequest,
org.apache.http.Header... headers)
Executes a bulk request using the Bulk API
See Bulk API on elastic.co
|
void |
bulkAsync(BulkRequest bulkRequest,
ActionListener<BulkResponse> listener,
org.apache.http.Header... headers)
Asynchronously executes a bulk request using the Bulk API
See Bulk API on elastic.co
|
ClearScrollResponse |
clearScroll(ClearScrollRequest clearScrollRequest,
org.apache.http.Header... headers)
Clears one or more scroll ids using the Clear Scroll api
See
Clear Scroll API on elastic.co
|
void |
clearScrollAsync(ClearScrollRequest clearScrollRequest,
ActionListener<ClearScrollResponse> listener,
org.apache.http.Header... headers)
Asynchronously clears one or more scroll ids using the Clear Scroll api
See
Clear Scroll API on elastic.co
|
void |
close() |
DeleteResponse |
delete(DeleteRequest deleteRequest,
org.apache.http.Header... headers)
Deletes a document by id using the Delete api
See Delete API on elastic.co
|
void |
deleteAsync(DeleteRequest deleteRequest,
ActionListener<DeleteResponse> listener,
org.apache.http.Header... headers)
Asynchronously deletes a document by id using the Delete api
See Delete API on elastic.co
|
boolean |
exists(GetRequest getRequest,
org.apache.http.Header... headers)
Checks for the existence of a document.
|
void |
existsAsync(GetRequest getRequest,
ActionListener<java.lang.Boolean> listener,
org.apache.http.Header... headers)
Asynchronously checks for the existence of a document.
|
GetResponse |
get(GetRequest getRequest,
org.apache.http.Header... headers)
Retrieves a document by id using the Get API
See Get API on elastic.co
|
void |
getAsync(GetRequest getRequest,
ActionListener<GetResponse> listener,
org.apache.http.Header... headers)
Asynchronously retrieves a document by id using the Get API
See Get API on elastic.co
|
RestClient |
getLowLevelClient()
Returns the low-level client that the current high-level client instance is using to perform requests
|
IndexResponse |
index(IndexRequest indexRequest,
org.apache.http.Header... headers)
Index a document using the Index API
See Index API on elastic.co
|
void |
indexAsync(IndexRequest indexRequest,
ActionListener<IndexResponse> listener,
org.apache.http.Header... headers)
Asynchronously index a document using the Index API
See Index API on elastic.co
|
MainResponse |
info(org.apache.http.Header... headers)
Get the cluster info otherwise provided when sending an HTTP request to port 9200
|
protected <Resp> Resp |
parseEntity(org.apache.http.HttpEntity entity,
CheckedFunction<XContentParser,Resp,java.io.IOException> entityParser) |
protected ElasticsearchStatusException |
parseResponseException(ResponseException responseException)
Converts a
ResponseException obtained from the low level REST client into an ElasticsearchException . |
protected <Req extends ActionRequest,Resp> |
performRequest(Req request,
CheckedFunction<Req,Request,java.io.IOException> requestConverter,
CheckedFunction<Response,Resp,java.io.IOException> responseConverter,
java.util.Set<java.lang.Integer> ignores,
org.apache.http.Header... headers) |
protected <Req extends ActionRequest,Resp> |
performRequestAndParseEntity(Req request,
CheckedFunction<Req,Request,java.io.IOException> requestConverter,
CheckedFunction<XContentParser,Resp,java.io.IOException> entityParser,
java.util.Set<java.lang.Integer> ignores,
org.apache.http.Header... headers) |
protected <Req extends ActionRequest,Resp> |
performRequestAsync(Req request,
CheckedFunction<Req,Request,java.io.IOException> requestConverter,
CheckedFunction<Response,Resp,java.io.IOException> responseConverter,
ActionListener<Resp> listener,
java.util.Set<java.lang.Integer> ignores,
org.apache.http.Header... headers) |
protected <Req extends ActionRequest,Resp> |
performRequestAsyncAndParseEntity(Req request,
CheckedFunction<Req,Request,java.io.IOException> requestConverter,
CheckedFunction<XContentParser,Resp,java.io.IOException> entityParser,
ActionListener<Resp> listener,
java.util.Set<java.lang.Integer> ignores,
org.apache.http.Header... headers) |
boolean |
ping(org.apache.http.Header... headers)
Pings the remote Elasticsearch cluster and returns true if the ping succeeded, false otherwise
|
SearchResponse |
search(SearchRequest searchRequest,
org.apache.http.Header... headers)
Executes a search using the Search api
See Search API on elastic.co
|
void |
searchAsync(SearchRequest searchRequest,
ActionListener<SearchResponse> listener,
org.apache.http.Header... headers)
Asynchronously executes a search using the Search api
See Search API on elastic.co
|
SearchResponse |
searchScroll(SearchScrollRequest searchScrollRequest,
org.apache.http.Header... headers)
Executes a search using the Search Scroll api
See Search Scroll
API on elastic.co
|
void |
searchScrollAsync(SearchScrollRequest searchScrollRequest,
ActionListener<SearchResponse> listener,
org.apache.http.Header... headers)
Asynchronously executes a search using the Search Scroll api
See Search Scroll
API on elastic.co
|
UpdateResponse |
update(UpdateRequest updateRequest,
org.apache.http.Header... headers)
Updates a document using the Update API
|
void |
updateAsync(UpdateRequest updateRequest,
ActionListener<UpdateResponse> listener,
org.apache.http.Header... headers)
Asynchronously updates a document using the Update API
|
public RestHighLevelClient(RestClientBuilder restClientBuilder)
RestHighLevelClient
given the low level RestClientBuilder
that allows to build the
RestClient
to be used to perform requests.protected RestHighLevelClient(RestClientBuilder restClientBuilder, java.util.List<NamedXContentRegistry.Entry> namedXContentEntries)
RestHighLevelClient
given the low level RestClientBuilder
that allows to build the
RestClient
to be used to perform requests and parsers for custom response sections added to Elasticsearch through plugins.protected RestHighLevelClient(RestClient restClient, CheckedConsumer<RestClient,java.io.IOException> doClose, java.util.List<NamedXContentRegistry.Entry> namedXContentEntries)
RestHighLevelClient
given the low level RestClient
that it should use to perform requests and
a list of entries that allow to parse custom response sections added to Elasticsearch through plugins.
This constructor can be called by subclasses in case an externally created low-level REST client needs to be provided.
The consumer argument allows to control what needs to be done when the close()
method is called.
Also subclasses can provide parsers for custom response sections added to Elasticsearch through plugins.public RestClient getLowLevelClient()
public final void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public BulkResponse bulk(BulkRequest bulkRequest, org.apache.http.Header... headers) throws java.io.IOException
java.io.IOException
public void bulkAsync(BulkRequest bulkRequest, ActionListener<BulkResponse> listener, org.apache.http.Header... headers)
public boolean ping(org.apache.http.Header... headers) throws java.io.IOException
java.io.IOException
public MainResponse info(org.apache.http.Header... headers) throws java.io.IOException
java.io.IOException
public GetResponse get(GetRequest getRequest, org.apache.http.Header... headers) throws java.io.IOException
java.io.IOException
public void getAsync(GetRequest getRequest, ActionListener<GetResponse> listener, org.apache.http.Header... headers)
public boolean exists(GetRequest getRequest, org.apache.http.Header... headers) throws java.io.IOException
java.io.IOException
public void existsAsync(GetRequest getRequest, ActionListener<java.lang.Boolean> listener, org.apache.http.Header... headers)
public IndexResponse index(IndexRequest indexRequest, org.apache.http.Header... headers) throws java.io.IOException
java.io.IOException
public void indexAsync(IndexRequest indexRequest, ActionListener<IndexResponse> listener, org.apache.http.Header... headers)
public UpdateResponse update(UpdateRequest updateRequest, org.apache.http.Header... headers) throws java.io.IOException
java.io.IOException
public void updateAsync(UpdateRequest updateRequest, ActionListener<UpdateResponse> listener, org.apache.http.Header... headers)
public DeleteResponse delete(DeleteRequest deleteRequest, org.apache.http.Header... headers) throws java.io.IOException
java.io.IOException
public void deleteAsync(DeleteRequest deleteRequest, ActionListener<DeleteResponse> listener, org.apache.http.Header... headers)
public SearchResponse search(SearchRequest searchRequest, org.apache.http.Header... headers) throws java.io.IOException
java.io.IOException
public void searchAsync(SearchRequest searchRequest, ActionListener<SearchResponse> listener, org.apache.http.Header... headers)
public SearchResponse searchScroll(SearchScrollRequest searchScrollRequest, org.apache.http.Header... headers) throws java.io.IOException
java.io.IOException
public void searchScrollAsync(SearchScrollRequest searchScrollRequest, ActionListener<SearchResponse> listener, org.apache.http.Header... headers)
public ClearScrollResponse clearScroll(ClearScrollRequest clearScrollRequest, org.apache.http.Header... headers) throws java.io.IOException
java.io.IOException
public void clearScrollAsync(ClearScrollRequest clearScrollRequest, ActionListener<ClearScrollResponse> listener, org.apache.http.Header... headers)
protected <Req extends ActionRequest,Resp> Resp performRequestAndParseEntity(Req request, CheckedFunction<Req,Request,java.io.IOException> requestConverter, CheckedFunction<XContentParser,Resp,java.io.IOException> entityParser, java.util.Set<java.lang.Integer> ignores, org.apache.http.Header... headers) throws java.io.IOException
java.io.IOException
protected <Req extends ActionRequest,Resp> Resp performRequest(Req request, CheckedFunction<Req,Request,java.io.IOException> requestConverter, CheckedFunction<Response,Resp,java.io.IOException> responseConverter, java.util.Set<java.lang.Integer> ignores, org.apache.http.Header... headers) throws java.io.IOException
java.io.IOException
protected <Req extends ActionRequest,Resp> void performRequestAsyncAndParseEntity(Req request, CheckedFunction<Req,Request,java.io.IOException> requestConverter, CheckedFunction<XContentParser,Resp,java.io.IOException> entityParser, ActionListener<Resp> listener, java.util.Set<java.lang.Integer> ignores, org.apache.http.Header... headers)
protected <Req extends ActionRequest,Resp> void performRequestAsync(Req request, CheckedFunction<Req,Request,java.io.IOException> requestConverter, CheckedFunction<Response,Resp,java.io.IOException> responseConverter, ActionListener<Resp> listener, java.util.Set<java.lang.Integer> ignores, org.apache.http.Header... headers)
protected ElasticsearchStatusException parseResponseException(ResponseException responseException)
ResponseException
obtained from the low level REST client into an ElasticsearchException
.
If a response body was returned, tries to parse it as an error returned from Elasticsearch.
If no response body was returned or anything goes wrong while parsing the error, returns a new ElasticsearchStatusException
that wraps the original ResponseException
. The potential exception obtained while parsing is added to the returned
exception as a suppressed exception. This method is guaranteed to not throw any exception eventually thrown while parsing.protected <Resp> Resp parseEntity(org.apache.http.HttpEntity entity, CheckedFunction<XContentParser,Resp,java.io.IOException> entityParser) throws java.io.IOException
java.io.IOException