美文网首页
es 查询 | bool query

es 查询 | bool query

作者: 末日声箫 | 来源:发表于2019-08-05 18:27 被阅读0次

    官网 : A query that matches documents matching boolean combinations of other queries
    简单的说就是几种must,filter,should,must_not 这几种查询的组合
    其中

    • must:有相关性得分分析 类似and
    • filter:无相关性得分分析 类似and
    • should:有相关性得分,类似or
    • must_not: 有相关性得分,类似not
      示例:
    
    get index/ _search
    {
      "query": {
        "bool" : {
          "must" : {
            "term" : { "user" : "zhao" }
          },
          "filter": {
            "term" : { "sex" : "男" }
          },
          "must_not" : {
            "range" : {
              "age" : { "gte" : 10, "lte" : 20 }
            }
          },
          "should" : [
            { "term" : { "tag" : "hi" } },
            { "term" : { "tag" : "elasticsearch" } }
          ]
        }
      }
    }
    

    如上面的查询:就是查询 user匹配"zhao"且sex为"男"且(te个应该匹配“hi”和“elasticsearch”其中一个)并且age 不在 【10,20】这个区间的数据

    相关文章

      网友评论

          本文标题:es 查询 | bool query

          本文链接:https://www.haomeiwen.com/subject/ohhvdctx.html