我正在设置基于ElasticSearch的自动完成功能。我已经建立了自动完成功能,但是它有一个错误,它会从搜索字符串中删除最后一个字符。
例如如果我搜索“ CBL”,那么它将搜索“ CB”并返回以下结果。
C.B.BUILDERS AND CONSTRUCTIONS Private Limited
CB BUSINESS SOLUTION PRIVATE LIMITED
C.B.CHAINS LIMITED
C.B. CHEMICALS LTD
C B COMPUSYSTEMS PRIVATE LIMITED
根据功能,它应该返回低于结果的位置。
CBL DATA RECOVERY TECHNOLOGIES PRIVATE LIMITED
CBL DATA SCIENCE PRIVATE LIMITED
CBL GLOBAL INDUSTRIES PRIVATE LIMITED
CBL INVESTMENTS LTD
CBL Trading Concepts Private Limited
这是我应用的索引设置和配置。
{
"settings": {
"index": {
"analysis": {
"filter": {},
"analyzer": {
"keyword_analyzer": {
"filter": [
"lowercase",
"asciifolding",
"trim"
],
"char_filter": [],
"type": "custom",
"tokenizer": "keyword"
},
"edge_ngram_analyzer": {
"filter": [
"lowercase"
],
"tokenizer": "edge_ngram_tokenizer"
},
"edge_ngram_search_analyzer": {
"tokenizer": "lowercase"
}
},
"tokenizer": {
"edge_ngram_tokenizer": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 5,
"token_chars": [
"letter"
]
}
}
}
}
},
"mappings": {
"_doc": {
"properties": {
"CleanedCompanyName": {
"type": "text",
"fields": {
"keywordstring": {
"type": "text",
"analyzer": "keyword_analyzer"
},
"edgengram": {
"type": "text",
"analyzer": "edge_ngram_analyzer",
"search_analyzer": "edge_ngram_search_analyzer"
},
"completion": {
"type": "completion"
}
},
"analyzer": "standard"
}
}
}
}
}
下面是我正在使用的搜索查询。
{ "suggest":
{ "companyname-suggest-fuzzy":
{ "prefix": "CBL",
"completion": {
"field": "CleanedCompanyName.completion",
"fuzzy": {
"fuzziness": "AUTO"
}
}
}
}
}