正如 javaanna 在评论中提到的那样_证实API。以下是我的本地弹性(版本 1.6)上的工作原理:
curl -XGET 'http://localhost:9201/pl/_validate/query?explain&pretty' -d'
{
"query": {
"query_string": {
"query": "a OR (b AND c) OR (d AND NOT(e or f))",
"default_field": "t"
}
}
}
'
pl
是我的集群上的索引名称。不同的索引可能有不同的分析器,这就是为什么查询验证在索引的范围内执行的原因。
上述curl的结果如下:
{
"valid" : true,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"explanations" : [ {
"index" : "pl",
"valid" : true,
"explanation" : "filtered(t:a (+t:b +t:c) (+t:d -(t:e t:or t:f)))->cache(org.elasticsearch.index.search.nested.NonNestedDocsFilter@ce2d82f1)"
} ]
}
我做了一个OR
故意小写,正如您在解释中看到的,它被解释为标记而不是运算符。
至于解释的解释。格式类似于+-
运营商 of query string
query:
- ( 和 ) 字符开始和结束
bool query
- + 前缀表示将出现在的子句
must
- - 前缀表示将出现在的子句
must_not
- 没有前缀意味着它将位于
should
(with default_operator
等于OR
)
所以上面将等价于下面:
{
"bool" : {
"should" : [
{
"term" : { "t" : "a" }
},
{
"bool": {
"must": [
{
"term" : { "t" : "b" }
},
{
"term" : { "t" : "c" }
}
]
}
},
{
"bool": {
"must": {
"term" : { "t" : "d" }
},
"must_not": {
"bool": {
"should": [
{
"term" : { "t" : "e" }
},
{
"term" : { "t" : "or" }
},
{
"term" : { "t" : "f" }
}
]
}
}
}
}
]
}
}
I used _validate
api 相当繁重,调试复杂filtered
具有许多条件的查询。如果您想检查分析器如何标记化输入(例如 url)或某些过滤器是否被缓存,那么它特别有用。
还有一个很棒的参数rewrite
直到现在我才意识到这一点,这使得解释更加详细,显示了将要执行的实际 Lucene 查询。