Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to explain the query in elasticsearch

Tags:

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(*:*)" } ] } 
like image 463
gao jiawei Avatar asked Nov 15 '15 14:11

gao jiawei


People also ask

What is a query in Elasticsearch?

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.

How do you query an Elasticsearch index?

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 .

How to use Elasticsearch API to search and aggregate data?

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.

What are the different types of queries in Elasticsearch?

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.

How do I search an index in Elasticsearch?

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.

What is the Elasticsearch query DSL?

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


1 Answers

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

like image 133
BenG Avatar answered Oct 14 '22 14:10

BenG