如何提高短语匹配但仅限于特定领域?

How to boost a phrase matching but just in certain field?

我想通过匹配短语来提升查询,但我希望它只在特定字段中搜索。到目前为止,我有以下查询

{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "_all": {
              "query": "string",
              "boost": 5
            }
          }
        }
      ]
    }
  }
}

但是这 returns 几个结果,因为我没有指定应该搜索的字段。我尝试了另一种方法:

{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "_all": {
              "query": "string",
              "fields": [
                "filed_name"
              ],
              "boost": 5
            }
          }
        }
      ]
    }
  }
}

但我收到错误

[match] query does not support [fields]]

您可以使用multi match查询并在特定字段中使用phrase typematch_phrase

{
  "query": {
    "multi_match": {
      "query": "some string",
      "fields": ["title","summary"],
      "type": "phrase"
    }
  }
}