【发布时间】:2020-08-24 21:32:55
【问题描述】:
我正在使用如下复合查询查询包含 300 条记录的弹性索引:
GET my_index/_search
{
"size": 10,
"query": {
"bool": {
"should": [
{
"bool": {
"should": [
{
"multi_match": {
"query": "card",
"fields": [
"title^1.0"
]
}
}
],
"must": {
"term": {
"_index": {
"value": "my_index"
}
}
}
}
}
]
}
}
}
must on index 是因为这可能是一个多索引查询,具体取决于某些业务逻辑(must 很可能应该是一个过滤器,我可以更改它,但这不是我的问题的一部分。我得到相同的结果也有过滤器)。
虽然我希望这会返回与 should 子句匹配的文档,但我会返回索引中的所有文档 (300)
为什么会这样?
【问题讨论】:
-
你有没有机会浏览我的答案,期待得到你的反馈:)
-
嗨 Bhavya,问题是我们应该使用 must 查询或 filter 查询。在您的示例中,没有 should 子句。我的问题的解决方案是在请求中使用 minimumShouldMatch 字段。
标签: elasticsearch elasticsearch-dsl