ES基礎三 條件搜索


(1)bool:must,must_not,should,組合多個過濾條件 (2)bool可以嵌套 (3)相當於SQL中的多個and條件:當你把搜索語法學好了以后,基本可以實現部分常用的sql語法對應的功能    補充,在kibana中一般filter沒有只能提示了。可以先在query 直接寫。
should 當一個條件是是必須含有,兩個條件是滿足一個即可。綜合前兩句是,至少滿足一個條件即可。
GET /forum/article/_search
{
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "should": [
            {
              "term": {
                "postDate": "2017-01-01"
              }
            },
            {
              "term": {
                "articleID": "XHDK-A-1293-#fJ3"
              }
            }
          ],
          "must_not": [
            {
              "term": {
                "postDate": "2017-01-02"
              }
            }
          ]
        }
      }
    }
  }
}

上述查詢是查出

("postDate": "2017-01-01" or "articleID": "XHDK-A-1293-#fJ3") and !("postDate": "2017-01-02")

當需要嵌套是,不能直接bool嵌套,bool是嵌套在should,must,must_not里面的
GET /forum/article/_search
{
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "should": [
            {
              "term": {
                "postDate": "2017-01-01"
              }
            },
            {
              "term": {
                "articleID": "XHDK-A-1293-#fJ3"
              }
            }
          ],
          "must": [
            {
              "term": {
                "postDate": "2017-01-02"
              }
            },
            {
              "bool": {
                "should": [
                  {
                    "term": {
                      "_id": 3 } } ] } } ] } } }
  }
}

 

 


免責聲明!

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



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