The explain api computes a score explanation for a query and a specific document. This can give useful feedback whether a document matches or didn’t match a specific query.
ExplainRequest expects an
index and an
id to specify a certain document,
and a query represented by
QueryBuilder to run against it (the way of building queries).
ExplainRequest request = new ExplainRequest("contributors", "1"); request.query(QueryBuilders.termQuery("user", "tanguy"));
Use the preference parameter e.g. to execute the search to prefer local shards. The default is to randomize across shards.
Set to true to retrieve the _source of the document explained. You can also retrieve part of the document by using _source_include & _source_exclude (see Get API for more details)
explain method executes the request synchronously:
ExplainResponse response = client.explain(request, RequestOptions.DEFAULT);
explainAsync method executes the request asynchronously,
calling the provided
ActionListener when the response is ready:
The asynchronous method does not block and returns immediately. Once the request
ActionListener is called back using the
if the execution successfully completed or using the
onFailure method if
A typical listener for
ExplainResponse is constructed as follows:
ExplainResponse contains the following information:
The index name of the explained document.
The id of the explained document.
Indicates whether or not the explained document exists.
Indicates whether or not there is a match between the explained document and
the provided query (the
Indicates whether or not there exists a lucene
Get the lucene
GetResult contains two maps internally to store the fetched
_source and stored fields.
You can use the following methods to get them: