第50节:初识搜索引擎_上机动手实战多搜索条件组合查询

课程大纲

 

GET /website/article/_search

{

  "query": {

    "bool": {

      "must": [

        {

          "match": {

            "title": "elasticsearch"

          }

        }

扫描二维码关注公众号,回复: 5420498 查看本文章

      ],

      "should": [

        {

          "match": {

            "content": "elasticsearch"

          }

        }

      ],

      "must_not": [

        {

          "match": {

            "author_id": 111

          }

        }

      ]

    }

  }

}

 

{

    "bool": {

        "must":     { "match": { "title": "how to make millions" }},

        "must_not": { "match": { "tag":   "spam" }},

        "should": [

            { "match": { "tag": "starred" }}

        ],

        "filter": {

          "range": { "date": { "gte": "2014-01-01" }}

        }

    }

}

 

bool

must,must_not,should,filter

 

每个子查询都会计算一个document针对它的相关度分数,然后bool综合所有分数,合并为一个分数,当然filter是不会计算分数的

 

{

    "bool": {

        "must":     { "match": { "title": "how to make millions" }},

        "must_not": { "match": { "tag":   "spam" }},

        "should": [

            { "match": { "tag": "starred" }}

        ],

        "filter": {

          "bool": {

              "must": [

                  { "range": { "date": { "gte": "2014-01-01" }}},

                  { "range": { "price": { "lte": 29.99 }}}

              ],

              "must_not": [

                  { "term": { "category": "ebooks" }}

              ]

          }

        }

    }

}

 

GET /company/employee/_search

{//注意单纯的filter ,必须添加constant_score

  "query": {

    "constant_score": {

      "filter": {

        "range": {

          "age": {

            "gte": 30

          }

        }

      }

    }

  }

}

 

 

猜你喜欢

转载自blog.csdn.net/qq_35524586/article/details/88095657