Han*_*örr 8 lucene elasticsearch
有没有办法通过elasticsearch API 找出实际解析查询字符串查询的方式?您可以通过查看lucene查询语法手动执行此操作,但如果您可以查看解析器具有的实际结果的某些表示,那将非常好.
正如javanna在评论中提到的那样_validate 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"
}
}
}
'
Run Code Online (Sandbox Code Playgroud)
pl
是我的群集上的索引名称.不同的索引可能有不同的分析器,这就是查询验证在索引范围内执行的原因.
以上卷曲的结果如下:
{
"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)"
} ]
}
Run Code Online (Sandbox Code Playgroud)
我OR
故意制作了一个小写,正如你在解释中看到的那样,它被解释为一个标记而不是一个操作符.
至于解释的解释.格式类似于+-
运营商的query string
查询:
bool query
must
must_not
should
(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" }
}
]
}
}
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我使用_validate
api来调试filtered
具有许多条件的复杂查询.如果您想要检查分析器如何标记输入(如url)或缓存某些过滤器,它尤其有用.
还有一个令人敬畏的参数rewrite
,直到现在我还没有意识到,这使得解释更加详细,显示了将要执行的实际Lucene查询.
归档时间: |
|
查看次数: |
1470 次 |
最近记录: |