2016-04-29 31 views
0

假設我有一個由三個令牌組成的字符串:abc def ghi。Elasticsearch:通用令牌組合

我想執行一個查詢,以獲得精確匹配和它的變化,如:

ABC GHI DEF(以任何順序標記)

ABC DEF(缺少令牌)

ABC DEF JKL GHI(我的期望的令牌之間插入的任何令牌)(用在任何數量的其字符的錯誤標記)

AZC DZF GZZ

也就是說,我想要檢索具有確切標記,其變體和正確拼寫錯誤的文檔。

我試過一個匹配短語前綴查詢,但它並沒有在首字母標記中執行正則表達式,只是在最後一個標記中。

我試過regexp查詢,但它不執行標記之間的斜坡。

有人可以給我一些建議嗎?

在此先感謝。

回答

0

比方說,我指數像下面沒有特殊設置,分析儀,等了一個文件:

PUT my_index 
{ 
    "text": "abc def ghi" 
} 

那麼簡單match將做的工作

# exact search 
POST my_index/_search 
{ 
    "query": { 
    "match": { 
     "text": { 
     "query": "abd def ghi" 
     } 
    } 
    } 
} 
=> matches with score 0.26574233 

# tokens in any ordering 
POST my_index/_search 
{ 
    "query": { 
    "match": { 
     "text": { 
     "query": "abd ghi def" 
     } 
    } 
    } 
} 
=> matches with score 0.26574233 

# missing token 
POST my_index/_search 
{ 
    "query": { 
    "match": { 
     "text": { 
     "query": "abd def" 
     } 
    } 
    } 
} 
=> matches with score 0.2169777 

# any tokens inserted between my desired tokens 
POST my_index/_search 
{ 
    "query": { 
    "match": { 
     "text": { 
     "query": "abd ghi jkl def" 
     } 
    } 
    } 
} 
=> matches with score 0.093538016 

# tokens with errors in any number of its chars 
POST my_index/_search 
{ 
    "query": { 
    "match": { 
     "text": { 
     "query": "azc dzf gzz", 
     "fuzziness": 2 
     } 
    } 
    } 
} 
=> matches with score 0.25571066 
+0

是你可以試試這個出來嗎? – Val