參照這裏的例子 https://www.elastic.co/guide/en/elasticsearch/guide/current/ngrams-compound-words.htmlelasticsearch正克例如澄清
報價尋找「阿德勒」返回結果。 對「Adler」的搜索成爲adl,dle和ler三個詞的查詢:
但爲什麼查詢「Zdler」返回結果,即使zdl不是其中一個術語?
GET /my_index/my_type/_search
{
"query": {
"match": {
"text": {
"query": "zdler"
}
}
}
}
將匹配查詢應用於「Adler」上的搜索將返回預期的記錄。
但是,「Zdler」上的匹配查詢也返回記錄(因爲dle和ler匹配)。即使設置「minimum_should_match」:「100%」返回該記錄 - 預計不會
申請期限查詢的「阿德勒」搜索返回什麼 - 預計不會
POST /my_index/my_type/_search
{
"query": {
"term": {
"text": {
"value": "Adler"
}
}
}
}
如何實現返回只記錄搜索「Adler」而不是「Zdler」?
"settings": {
"index": {
"number_of_shards": "5",
"provided_name": "my_index",
"creation_date": "1501069624443",
"analysis": {
"filter": {
"trigrams_filter": {
"type": "ngram",
"min_gram": "3",
"max_gram": "3"
}
},
"analyzer": {
"trigrams": {
"filter": [
"lowercase",
"trigrams_filter"
],
"type": "custom",
"tokenizer": "standard"
}
}
},
"number_of_replicas": "1",
"uuid": "Z5BXi_RjTACzTsR_-Nu9tw",
"version": {
"created": "5040099"
}
}
}
並且這些映射
{
"my_index": {
"mappings": {
"my_type": {
"properties": {
"text": {
"type": "text",
"analyzer": "trigrams"
}
}
}
}
很簡單,因爲'dle'和'ler'也匹配 – Val