I have a complex query in elasticsearch. it's slow. I want to optimize it. but i can't know how to work . how to explain the query , like Sql explain.
i see elastichsearch _valite/query?explain . it can explain score. but I need to view 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(*:*)" } ] }
More Detail. In Elasticsearch, searching is carried out by using query based on JSON. A query is made up of two clauses − Leaf Query Clauses − These clauses are match, term or range, which look for a specific value in specific field.
You can use the search API to search and aggregate data stored in Elasticsearch data streams or indices. The API's query request body parameter accepts queries written in Query DSL. The following request searches my-index-000001 using a match query. This query matches documents with a user.id value of kimchy .
You can use the search API to search and aggregate data stored in Elasticsearch data streams or indices. The API’s query request body parameter accepts queries written in Query DSL. The following request searches my-index-000001 using a match query. This query matches documents with a user.id value of kimchy.
Elasticsearch supports a large number of queries. A query starts with a query key word and then has conditions and filters inside in the form of JSON object. The different types of queries have been described below. Match All Query. This is the most basic query; it returns all the content and with the score of 1.0 for every object.
You can use the search API to search and aggregate data stored in Elasticsearch data streams or indices. The API’s query request body parameter accepts queries written in Query DSL. The following request searches my-index-000001 using a match query.
Elasticsearch offers a powerful query DSL to define queries to execute against Elasticsearch. This DSL is based on JSON and is exposed in NEST in the form of both a Fluent API and an Object Initializer syntax The simplest of queries is the match_all query; this will return all documents, giving them all a _score of 1.0
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.
Add "explain": true
GET /_search { "explain": true, "query" : { "term" : { "user" : "kimchy" } } }
Explain Documentation
Profile API
Provides detailed timing information about the execution of individual components in a search request. It gives the user insight into how search requests are executed at a low level so that the user can understand why certain requests are slow, and take steps to improve them.
Add "profile": true
GET /_search { "profile": true, "query" : { "match" : { "user" : "kimchy" } } }
Profile Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With