【问题标题】:Elasticsearch - Avoid Word based and fuzzy based match when Phrase is matchedElasticsearch - 匹配短语时避免基于单词和基于模糊的匹配
【发布时间】:2018-12-27 14:49:37
【问题描述】:

我有一个查询,它搜索词组、词级别和搜索词的模糊性。 有没有一种方法可以在匹配精确短语时限制单词和模糊匹配? 开发的查询是:

PUT test/_doc/1
{
  "field1": "this is a test query - query",
  "field2": "best rest vest pest"
}

GET test/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "this is a test query",
            "type": "phrase",
            "slop": "2",
            "fields": []
          }
        },
        {
          "multi_match": {
            "query": "this is a test query",
            "analyzer": "whitespace",
            "fields": []
          }
        },
        {
          "multi_match": {
            "query": "this is a test query",
            "analyzer": "whitespace",
            "fuzziness": "AUTO",
            "fields": []
          }
        }
      ],
      "minimum_should_match": 1
    }
  },
  "highlight": {
    "type": "unified",
    "fields": {
      "*": {}
    }
  }
}

得到的结果(只有Highlight)是:

"field1": [ "this is a test query - 查询" ], "field2": [ "best rest 背心 害虫" ]

我不希望在匹配“这是一个测试查询”短语时突出显示“best”、“rest”、“vest”和“pest”

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    将您的词组搜索放在must 中,并将其他两个条件保留在should 中。查询规划器应该足够聪明,可以为您解决这个问题。

    【讨论】:

    • 您能举个例子吗?
    • 您能否举一个更具体的例子,比如 3 个文档以及您想要匹配和不想匹配的内容?我不确定“在匹​​配精确短语时限制单词和模糊匹配”应该如何解决,因为短语匹配是最严格的匹配;一旦与其他 2 个匹配,就会增加分数。
    • 嗨@xeraa,感谢您的回复。我已经索引了两个文档{“field1”:“这是一个测试查询 - 查询”,“field2”:“最佳休息背心害虫”}
    • 这是我的查询,重点是:"field1": [ "this is a 测试 查询 - 查询" ], "field2": [ "best rest 背心 pest" ] 我不想在匹配“这是一个测试查询”短语时突出显示“best”、“rest”、“vest”和“pest”
    • 我已将您的示例添加到原始问题中。请描述您期望在查询中有所不同的地方。我认为将第一个应该放入比赛是不够的?
    猜你喜欢
    • 1970-01-01
    • 2019-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    相关资源
    最近更新 更多