我有一个像这样的查询字符串:
"(( name_first.raw:goda )) AND !( _uid:*566ade1cec8d83647a000061* OR _uid:*566ade1cec8d83647a000062* OR _uid:*566ade1cec8d83647a000063* OR _uid:*566ade1cec8d83647a000064*)"
如何以更有效的方式编写此查询?
答案 0 :(得分:1)
我认为这会奏效,
GET /yourindex/yourType/_search
{
"query": {
"filtered": {
"query": {
"match": {
"name_first.raw": "goda"
}
},
"filter": {
"bool": {
"must_not": [
{
"terms": {
"_uid": [
"566ade1cec8d83647a000061",
"566ade1cec8d83647a000062",
"566ade1cec8d83647a000063"
]
}
}
]
}
}
}
}
}
答案 1 :(得分:1)
您可以使用以下查询:
POST <index>/<type>/_search
{
"query": {
"filtered": {
"query": {
"term": {
"name_first.raw": "goda"
}
},
"filter": {
"bool": {
"must_not": [
{
"terms": {
"_uid": [
"566ade1cec8d83647a000061",
"566ade1cec8d83647a000062",
"566ade1cec8d83647a000063"
]
}
}
]
}
}
}
}
}
答案 2 :(得分:0)
这应该有用,(+
=&gt;&#34;必须&#34;和-
=&gt;&#34; must_not&#34;)
"+name_first.raw:goda -_uid:*566ade1cec8d83647a000061* -_uid:*566ade1cec8d83647a000062* -_uid:*566ade1cec8d83647a000063* -_uid:*566ade1cec8d83647a000064*"
令我担心的是,领先通配符的处理可能会真正减缓这种情况。你绝对需要通配符吗?如果您发现自己需要对此进行优化,并且可以开始使用DSL,请查看post_filter以了解排除标准。