我有这样的查询:
{
"size": 4,
"query": {
"bool": {
"should": [{
"terms": { "property": ["iPhone earbuds", "iPhone 6 case"] }
}, {
"constant_score": {
"filter": { "match_all": {} },
"boost": 0
}
}],
"must_not": {
"ids": {
"values": ["doc 1", "doc 2"],
"boost": 0
}
},
"minimum_should_match": 1
}
},
"sort": []
}
一些空对象只是我如何构建查询JSON的人工产物,它们在大多数情况下都具有含义,这只是我找到的最简单的示例。
为什么会以分数= 0返回文档,我该如何阻止这种情况发生?
最佳答案
那会是
{
"constant_score": {
"filter": { "match_all": {} },
"boost": 0
}
}
匹配所有内容,这部分的得分为0;这也满足您的
"minimum_should_match": 1
规则。您可以进一步简化示例(但我仍然不确定此查询要实现什么):
PUT /test/test/1
{
"foo": "iphone"
}
PUT /test/test/2
{
"foo": "iphone earbuds"
}
PUT /test/test/3
{
"foo": "iphone case"
}
PUT /test/test/4
{
"foo": "bar"
}
POST /test/_search
{
"query": {
"bool": {
"should": [
{
"terms": { "foo": ["iphone"] }
}, {
"constant_score": {
"filter": { "match_all": {} },
"boost": 0
}
}
],
"minimum_should_match": 1
}
}
}
DELETE /test
关于elasticsearch - Elasticsearch如何排除分数= 0文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41473796/