nog*_*o0d 4 boolean range elasticsearch
我是弹性搜索的新手,所以我的例子是:
bool过滤器有3个部分:
must
All of these clauses must match. The equivalent of AND.
must_not
All of these clauses must not match. The equivalent of NOT.
should
At least one of these clauses must match. The equivalent of OR.
如何预先形成一个should_not查询?
提前致谢 :)
Prz*_*wak 15
为了获得类似"should_not"的内容,请尝试以下查询:
GET /bank/account/_search
{
"size": 2000,
"query": {
"bool": {
"must": {
"match_all": {}
},
"should": {
"bool": {
"must_not": {
"match": {
"city": "XYZ"
}
}
}
}
}
}
}
在这种情况下,需要"必须"条款来检索所有结果(城市"XYZ"的结果也是如此),但该特定结果的分数降低.
这取决于您希望“ should_not”发挥作用的精确程度。
由于should大致等效于布尔OR(即,返回A或B或C为true的文档),因此想到“ should_not”的一种方法大致等效于NOT(A OR B OR C)。在布尔逻辑中,这与NOT A AND NOT B AND NOT C相同。在这种情况下,只需将所有子句添加到must_notbool过滤器的这一部分即可实现“ should_not”行为。
您可以应用一个 not 过滤器,然后应用一个should 过滤器来执行should_not 操作。
"filter": {
"not": {
"filter": {
"bool": {
"should": [
{}
]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7409 次 |
| 最近记录: |