多搜索条件组合查询

示例:

GET /website/article/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "title": "elasticsearch"
          }
        }
      ],
      "should": [
        {
          "match": {
            "content": "elasticsearch"
          }
        }
      ],
      "must_not": [
        {
          "match": {
            "author_id": 111
          }
        }
      ]
    }
  }
}

示例2:

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

  • must: 必须不配

  • must_not: 必须不匹配

  • should :可以匹配可以不匹配(如果多个should中包含多个,其中一个条件满足也ok)

  • filter:仅仅只是按照搜索条件过滤出需要的数据而已,不计算任何相关度分数,对相关度没有任何影响

Last updated

Was this helpful?