Daniel Buckle
Daniel Buckle

Reputation: 628

How to get full explanation of Elasticsearch query Java?

I'm currecntly trying to test out some new score functions on my Elasticsearch query but I'm not yielding the results I am expecting.

I found this on their site about explaining queries here

I can run as a curl command but does anyone know how to translate this to use the Java api?

Upvotes: 4

Views: 705

Answers (1)

Aerus
Aerus

Reputation: 4380

If you're using the ES5 Java API, you can get the explanation like this:

QueryBuilder query = matchAllQuery(); // your query

ExplainRequest request = new ExplainRequest("index", "type", "id").query(query);
ExplainResponse explainResponse = client.explain(request).actionGet();
Explanation explanation = explainResponse.getExplanation();

Where client is your org.elasticsearch.client.Client instance.

Upvotes: 4

Related Questions