zoukankan      html  css  js  c++  java
  • 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
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        }
      }
    }
     
  • 相关阅读:
    8 pandas模块,多层索引
    7 numpy 傅里叶,提取图片轮廓
    6 DataFrame处理丢失数据--数据清洗
    5 pandas模块,DataFrame类
    4 pandas模块,Series类
    3 numpy模块
    2 线性代数基础
    1 Ipython、Jupyter 入门
    jdk安装与环境变量配置(一劳永逸)
    对jsp可见域的变量感悟
  • 原文地址:https://www.cnblogs.com/javabeginer/p/13060219.html
Copyright © 2011-2022 走看看