elasticsearch 復合查詢


常用查詢
固定分數查詢

  127.0.0.1/_search(全文搜索)
     {
       "query":{
         "match"{
      "title":"elashsearch" //查詢標題含有elashsearch的字段

       }
    }
      }

 用固定分數查詢

 {
       "query":{
         "constant_score"{ //關鍵詞 
      "filter":{ //filter下寫查詢的語法
         "match"{ 
        "title":"elashsearch" //查詢標題含有elashsearch的字段

       }
         },
         "boost":1 //用來指定分數,可以不寫,會做一下緩存
       }
    }
      }

布爾查詢

{
    "query":{
       "bool":{
          "should"[//關鍵詞,應當滿足條件
        {  
          "match":{
             "author":"瓦力"
        }
          },
          {
            "match":{
            "title":"aaa"
          }
          
          }
      ]
      }
       }
     }

兩個match的關系為或,滿足一個即可

{
  "query":{
     "bool":{
       "must":[ //關鍵詞,為必須滿足條件
       {
          "match":{
         "author":"瓦力"
           }
       },
       {
        "match":{
           "title":"aaa"
         }
       }
     ],
     "filter":[  //過濾查找字段為1000的 可以不加
         {
          "term":{
              "word_count":1000
            }
         
         }
     ]
      }
   }
 }

管理為並且,兩者都滿足

 {
   "bool":{
      "must_not":{ //一定不能滿足條件
          "term":{ //指定字段為瓦力
         "author":"瓦力"
       }
    }
    }
 }

 


免責聲明!

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



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