【发布时间】:2021-06-19 09:16:17
【问题描述】:
我添加了 3 个文档
POST test/_doc
{"value": 1}
POST test/_doc
{"value": 2}
POST test/_doc
{"value": 3}
然后执行以下查询,我 expect 返回所有 3 个文档,其中与 should 子句匹配的文档排名更高
GET /test/_search
{
"query": {
"bool": {
"minimum_should_match": 0,
"should": [
{
"range": {
"value": {
"gte": 2
}
}
}
]
}
}
}
但我只得到 2 个文档(值 2,3)"minimum_should_match": 0, 没有任何效果,直到我在 bool 查询中添加 filter 或 must 子句,如下所示,
GET /test/_search
{
"query": {
"bool": {
"filter": [ { "match_all": { } } ],
"should": [
{
"range": {
"value": {
"gte": 2
}
}
}
]
}
}
}
我想要什么
在 bool 查询中,must 子句或 filter 子句为空或已填充,should 子句 must 不过滤任何文档但只参与排名,请分享我如何实现这一点,谢谢
【问题讨论】:
标签: elasticsearch elastic-stack elk booleanquery