我有以下 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-A4.0 的分數分配給winnerAthlete-B。
現在,當我將should查詢的第三行變成 amust時,查詢不匹配任何檔案,而我希望得到完全相同的結果。我無法理解為什么。我嘗試使用 ES_explain關鍵字來理解為什么這個查詢在使用時不匹配,must但它對我沒有幫助。
知道為什么用 a 重寫的這個查詢must沒有回傳任何內容,而該should版本確實回傳了預期的結果嗎?
uj5u.com熱心網友回復:
應該像 "OR" 一樣作業。它將回傳與任何子句匹配的檔案。
必須像 "AND" 一樣作業。檔案必須同時滿足這兩個條款。
您的查詢沒有回傳任何結果,因為沒有一個檔案的 id 為winnerAthlete-A 和winnerAthlete-B
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/523561.html
標籤:弹性搜索
上一篇:彈性云上的節點與分片
