我有以下ES查询:
{
"query": {
"bool": {
"should": [
{
"constant_score": {
"boost": 5,
"filter": {
"bool": {
"must": [
{
"ids": {
"values": [
"winnerAthlete-A"
]
}
},
{
"dis_max": {
"queries": [
{
"bool": {
"filter": {
"term": {
"isAthlete": true
}
}
}
},
{
"bool": {
"filter": {
"term": {
"isWinner": true
}
}
}
}
]
}
}
]
}
}
}
},
{
"constant_score": {
"boost": 4,
"filter": {
"bool": {
"must": [
{
"ids": {
"values": [
"winnerAthlete-B"
]
}
},
{
"dis_max": {
"queries": [
{
"bool": {
"filter": {
"term": {
"isAthlete": true
}
}
}
},
{
"bool": {
"filter": {
"term": {
"isWinner": true
}
}
}
}
]
}
}
]
}
}
}
}
]
}
}
}
它确实返回了我所期望的结果:2个文档winnerAthlete-A
和winnerAthlete-B
,将得分5.0分配给winnerAthlete-A
,将得分4.0分配给winnerAthlete-B
。
现在,当我将查询第三行的should
转换为must
时,该查询与任何文档都不匹配,而我期望得到完全相同的结果。我无法理解为什么。我曾尝试使用ES _explain
关键字来理解为什么在使用must
时该查询不匹配,但它没有帮助我。
知道为什么用must
重写的这个查询不返回任何东西,而should
版本却返回预期的结果吗?
1条答案
按热度按时间eaf3rand1#
Should的作用类似于“OR”。它将返回与任何子句匹配的文档。
Must的作用类似于“AND”。文档必须同时满足这两个子句。
您的查询未返回任何结果,因为不存在ID为winnerAthlete-A和winnerAthlete-B的单个文档