match_phrase 查询的模糊行为

Fuzziness behavior on a match_phrase query

几天前我得到了这个"problem"。我的索引中 运行 是一个 match_phrase 查询。一切都如预期的那样,直到我用多个单词名词进行了相同的搜索(在我使用单个单词名词之前,例如:大学)。我犯了一个拼写错误,搜索没有成功(未找到),如果我删除了一个单词(假设拼写正确的那个),搜索工作(找到)。

下面是我做的例子:

设置

PUT index1
{
  "mappings": {
    "myType": {
      "properties": {
        "field1": {
          "type": "string",
          "analyzer": "standard"
        }
      }
    }
  }
}

POST index1/myType/1
{
  "field1": "Commercial Banks"
}

案例一:单个名词搜索

GET index1/myType/_search
{
  "query": {
    "match": {
      "field1": {
        "type": "phrase", 
        "query": "comersial",
        "fuzziness": "AUTO"
      }
    }
  }
}

{
  "took": 16,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.19178303,
    "hits": [
      {
        "_index": "index1",
        "_type": "myType",
        "_id": "1",
        "_score": 0.19178303,
        "_source": {
          "field1": "Commercial Banks"
        }
      }
    ]
  }
}

案例二:多名词搜索

GET index1/myType/_search
{
  "query": {
    "match": {
      "field1": {
        "type": "phrase", 
        "query": "comersial banks",
        "fuzziness": "AUTO"
      }
    }
  }
}

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

那么,在第二种情况下,为什么我在执行 match_phrase 查询时找不到文档?有什么我想念的吗? 这些结果只是让我怀疑我所知道的。 我是否错误地使用了模糊搜索?我不确定这是不是一个问题,或者我是不理解这种行为的人。

非常感谢您阅读我的问题。我希望你能帮助我。

短语查询不支持模糊性。

目前,ES对此保持沉默,即它允许您指定参数但不会警告您它不受支持。 pull request (#18322) (related to issue #7764) 存在可以解决此问题的方法。一旦合并到 ES 5 中,此查询将出错。

在 5.0 的 breaking changes 文档中,我们可以看到不支持此功能:

The multi_match query will fail if fuzziness is used for cross_fields, phrase or phrase_prefix type. This parameter was undocumented and silently ignored before for these types of multi_match.