基于Request Body的term和bool查询

in ELK with 0 comment

精确匹配

使用term可以实现精确匹配

查询title为 Beautiful Mind 的电影

GET movies/_search
{
    "query": {
        "term": {
            "title": {
            "value": "Beautiful Mind"
            }
        }
    }
}

多条件或者判断

bool

  • must 条件同时成立
  • should 条件满足单一即可

查询出title或者genre中包含romance,并且年份在2010到2020的电影

GET movies/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "romance",
            "fields": ["title","genre"]
          }
        },
        {
          "range": {
            "year": {
              "gte": 2010,
              "lte": 2020
            }
          }
        }
      ]
    }
  }
}

查询出title或者genre中包含romance,或者年份在2010到2020的电影

GET movies/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "romance",
            "fields": ["title","genre"]
          }
        },
        {
          "range": {
            "year": {
              "gte": 2010,
              "lte": 2020
            }
          }
        }
      ]
    }
  }
}
Responses