How to explain a request in elasticsearch

I have a complex query in elasticsearch. he is slow. I want to optimize it. but I don’t know how to work. how to explain the query, as explained by Sql.

Do I see elastichsearch _valite / query? this may explain the estimate. but I need to view a detailed execution plan.

{ "post_filter": { "bool": { "should": [ { "bool": { "must": [ { "term": { "base.sysCode": "2801" } }, { "term": { "base.status": [ 12, 0 ] } } ] } } ] } }, "fields": [ "base.sysCode", "base.orderNo" ] } 

result

 { "valid": true, "_shards": { "total": 1, "successful": 1, "failed": 0 }, "explanations": [ { "index": "odi_bus_betad_2013", "valid": true, "explanation": "ConstantScore(*:*)" } ] } 
+5
source share
4 answers

Add "explain": true

 GET /_search { "explain": true, "query" : { "term" : { "user" : "kimchy" } } } 

Documentation

+4
source

Paste the profile keyword in your query if you are using the latest version:

 GET binary/_search { "profile": true, "query": { ... } } } 

If you have an X-Pack, you can use the GUI-based profiler to see where it is sluggish. Unfortunately, it is not available in the open source version, but this is only a more beautiful version of the output from the above - https://www.elastic.co/guide/en/kibana/5.6/xpack-profiler.html

You may be able to complete the 30-day trial or, if you're lucky, you may already have an X-Pack license.

+2
source

Using the API explanation here

Explanation The api computes an assessment explanation for the request and a specific document. This can provide useful information about whether the document matches or does not match a specific request.

+1
source

You did everything right. You executed your query with explain , and Elasticsearch showed you a detailed implementation plan in explanations .

However, the detailed implementation plan here does not seem to have any details; this is because you did not run the query at all. You only executed post_filter (the very first keyword in your example.)

Since you did not specify a query at all, Elasticsearch matches every document in your index and applies a constant account for all of them. That's why in explanations you see: "explanation": "ConstantScore(*:*)"

Since each document in your index has been mapped, the post_filter you post_filter applies to each of them. This in itself is already slow; to make it worse, mail filters are never cached. ( https://www.elastic.co/guide/en/elasticsearch/guide/current/_post_filter.html ) This way, explain will never tell you any filter or cache file for your example, even if it could.

So, to answer your question: explain has already returned the best detailed execution plan that Elasticsearch could offer, given your specific example. You can try a regular filter instead of post_filter to give Elasticsearch a chance to create caches and improve performance.

0
source

Source: https://habr.com/ru/post/1235995/


All Articles