【问题标题】:How to boost a phrase matching but just in certain field?如何提升短语匹配但仅在特定领域?
【发布时间】:2016-02-07 10:23:06
【问题描述】:

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

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

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

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

但我得到了错误

[匹配]查询不支持[字段]]

【问题讨论】:

    标签: elasticsearch match-phrase


    【解决方案1】:

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

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

    【讨论】:

    • 是的,谢谢@ChintanShah25!这就是我最终做的事情。您还可以通过这种方式包含模糊参数。例如: { "query": { "multi_match": { "query": "some string", "fields": ["title","summary"], "type": "phrase", "fuzziness": "AUTO " } } }
    猜你喜欢
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 2012-01-12
    • 2010-09-06
    • 1970-01-01
    相关资源
    最近更新 更多