elasticsearch must和should組合查詢


{"query": {
   "bool": {
     "should": [
       {"bool": {
         "must": [
           {}
         ]
       }
       },
       {"bool": {
         "must": [
           {}
         ]
       }}
     ]
   }
  }
}

 

bool 過濾

bool 過濾可以用來合並多個過濾條件查詢結果的布爾邏輯,它包含一下操作符:

  • must :: 多個查詢條件的完全匹配,相當於 and。
  • must_not :: 多個查詢條件的相反匹配,相當於 not。
  • should :: 至少有一個查詢條件匹配, 相當於 or。

這些參數可以分別繼承一個過濾條件或者一個過濾條件的數組:


    "bool": { 
        "must":     { "term": { "folder": "inbox" }}, 
        "must_not": { "term": { "tag":    "spam"  }}, 
        "should": [ 
                    { "term": { "starred": true   }}, 
                    { "term": { "unread":  true   }} 
        ] 
    } 
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM