Verify Queries
Queries can become very complex, especially after the combination of different analyzers and field mapping, will be some difficulty.
validate
API can verify that a query is legitimate.
GET /gb/tweet/_validate/query { "query": { "tweet" : { "match" : "really powerful" } } }
Above the return value of the request told us that this statement is illegal:
{ "valid" : false, "_shards" : { "total" : 1, "successful" : 1, "failed" : 0 } }
Understanding Error Messages
Want to know the specific statement is illegal error message, you need to add explain
parameters:
GET /gb/tweet/_validate/query?explain <1> { "query": { "tweet" : { "match" : "really powerful" } } }
<1> explain
parameters can provide more details wrong statement.
Obviously, we query statement match
with the location of the field name backwards:
{ "valid" : false, "_shards" : { ... }, "explanations" : [ { "index" : "gb", "valid" : false, "error" : "org.elasticsearch.index.query.QueryParsingException: [gb] No query registered for [tweet]" } ] }
Understanding query
If this is a legitimate statement, use explain
parameter may be returned with a reading of the description of the query, the query can help us understand how the ES is executed:
GET /_validate/query?explain { "query": { "match" : { "tweet" : "really powerful" } } }
explanation
It returns a description for each index, because each index will have different mapping relationships and Analyzer:
{ "valid" : true, "_shards" : { ... }, "explanations" : [ { "index" : "us", "valid" : true, "explanation" : "tweet:really tweet:powerful" }, { "index" : "gb", "valid" : true, "explanation" : "tweet:really tweet:power" } ] }
From return explanation
you will see match
how the query string for the "really powerful"
query, first of all, it split into two separate words are in the tweet
query field.
Further, the index us
in the two terms "really"
and "powerful"
, in the index gb
are split into "really"
and "power"
. This is because we in the index gb
used in the english
analyzer.
Reproduced in: https: //my.oschina.net/fusublog/blog/3057672