2016-05-16 96 views
0

几天前,我得到了这个“问题”。我在索引中运行match_phrase查询。一切都如预期,直到我用多个单词名词进行同样的搜索(在我使用单个单词名词之前,例如:大学)。如果我删除了一个单词(比如说拼写正确的单词),那么搜索工作(找到)会导致拼写错误,并且搜索不起作用(未找到)。match_phrase查询中的模糊行为

在这里有我做的例子:

的设置

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

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

案例1:单名词搜索

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" 
     } 
     } 
    ] 
    } 
} 

案例2:多个名词搜索

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查询时找不到文档?有什么我失踪? 这些结果只是让我怀疑我所知道的。 我使用模糊搜索吗?我不确定这是否是一个问题,或者我是不了解这种行为的人。

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

回答

2

短语查询不支持模糊性。

目前,ES对此没有提及,即允许您指定参数,但不会警告您不支持该参数。 A pull request (#18322)(与issue #7764有关)存在,可以解决此问题。一旦合并到ES 5中,该查询将会出错。

breaking changes文档5.0中,我们可以看到,这将不被支持:如果fuzziness用于cross_fieldsphrasephrase_prefix

multi_match查询将失败。对于这些类型的multi_match,此参数没有记录,并且没有提及。