2016-05-16 98 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,此參數沒有記錄,並且沒有提及。