如何找出弹性搜索结果解析一个query_string? [英] How to find out result of elasticsearch parsing a query_string?
问题描述
由于javanna在评论中提到了 _ validate api。以下是我的本地弹性(1.6版)的功能:
curl -XGET'http:// localhost:9201 / _ $ _ $$$$$$$$$$$$$ OR(d AND NOT(e或f)),
default_field:t
}
}
}
'
pl
是我的集群上的索引名称。不同的索引可以有不同的分析器,这就是为什么查询验证在索引的范围内执行。
以上卷曲的结果如下:
{
valid:true,
_shards:{
total:1,
success:1,
failed:0
},
explanation:[{
index:pl,
(t:a(+ t:b + t:c)(+ t:d - (t:et:或t:f))) - > cache(org.elasticsearch.index.search.nested.NonNestedDocsFilter@ce2d82f1)
}]
}
我在目的上制作了一个 OR
小写,正如您在说明中可以看到的,它被解释为一个令牌,而不是一个操作符。
关于解释的解释。格式类似于 + -
查询字符串的string-query.html#_boolean_operatorsrel =nofollow>运算符查询:
- (和)字符开始和结束
bool query
- +前缀表示将在
必须
- - 前缀为
must_not
- 没有前缀意味着它将在
应该
(与default_operator
等于OR
)
所以上面将相当于以下内容:
{
bool:{
should:[
{
term {t:a}
},
{
bool:{
必须:[
{
:{t:b}
},
{
term:{t:c}
]
}
},
{
bool:{
必须:{
term:{ t:d}
},
must_not:{
bool:{
should:[
{
term:{t:e}
},
{
term:{t:or}
},
{
term:{t:f}
}
]
}
}
}
}
]
}
}
我使用 _validate
api相当大地调试复杂的过滤
查询有许多条件。如果您想要检查分析器如何将URL输入如url或某些过滤器进行缓存,则特别有用。
还有一个非常棒的参数重写
到目前为止我还没有意识到这一点,这将使得更详细的说明显示将执行的实际Lucene查询。
Is there a way to find out via the elasticsearch API how a query string query is actually parsed? You can do that manually by looking at the lucene query syntax, but it would be really nice if you could look at some representation of the actual results the parser has.
As javanna mentioned in comments there's _validate api. Here's what works on my local elastic (version 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
is name of index on my cluster. Different index could have different analyzers, that's why query validation is executed in a scope of an index.
The result of the above curl is following:
{
"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)"
} ]
}
I made one OR
lowercase on purpose and as you can see in explanation, it is interpreted as a token and not as a operator.
As for interpretation of the explanation. Format is similar to +-
operators of query string
query:
- ( and ) characters start and end
bool query
- + prefix means clause that will be in
must
- - prefix means clause that will be in
must_not
- no prefix means that it will be in
should
(withdefault_operator
equal toOR
)
So above will be equivalent to following:
{
"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 quite heavily to debug complex filtered
queries with many conditions. It is especially useful if you want to check how analyzer tokenized input like an url or if some filter is cached.
There's also an awesome parameter rewrite
that I was not aware of until now, which causes the explanation to be even more detailed showing the actual Lucene query that will be executed.
这篇关于如何找出弹性搜索结果解析一个query_string?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!