当前位置:   article > 正文

Elasticsearch结构化搜索基于bool组合多个filter条件来搜索数据_elasticsearch 多个filter条件只需要满足一个

elasticsearch 多个filter条件只需要满足一个

Elasticsearch结构化搜索 term filter来搜索数据
filter执行原理

搜索发帖日期为2017-01-01,或者帖子ID为XHDK-A-1293-#fJ3的帖子,同时要求帖子的发帖日期绝对不为2017-01-02

GET /post/_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"
            }
          }
        }
      }
    }
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

搜索帖子ID为XHDK-A-1293-#fJ3,或者是帖子ID为JODL-X-1937-#pV7而且发帖日期为2017-01-01的帖子

{
  "query": {
    "constant_score": {
      "filter": {
           "bool": {
             "should":[
                  {
                    "term":{
                      "articleID" :"XHDK-A-1293-#fJ3"
                    }
                  },
                  {
                    "bool":{
                     "must":[
                          {
                            "term":{
                              "articleID" :"JODL-X-1937#-#pV7"
                            }
                          },
                          {
                            "term":{
                              "postDate" :"2017-01-01"
                            }
                          }
                      ]
                    }
                  }
              ]
           }
      }
    }
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

should 中匹配任意一个就行,must_not必须不匹配 ,
must 必须匹配

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/409899
推荐阅读
相关标签
  

闽ICP备14008679号