如何从一开始就划分ElasticSearch查询

时间:2018-08-14 08:43:18

标签: elasticsearch

当执行这样的查询时;

GET /library/books/_search
{
  "query": {
    "match": {
      "title": "quick brown fox"
    }
  }
}

,它搜索"quick" or "brown" or "fox"

但是我想通过"quick" or "quick brown" or "quick brown fox"搜索

因为我不需要“棕狐”。

我如何轻松地做到这一点?

1 个答案:

答案 0 :(得分:1)

您可以使用match_phrase这样操作:

GET /library/books/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "title": "quick"
          }
        },
        {
          "match_phrase": {
            "title": "quick brown"
          }
        },
        {
          "match_phrase": {
            "title": "quick brown fox"
          }
        }
      ]
    }
  }
}