我正在使用elasticsearch在java中进行自动完成,所以我使用以下代码构建并映射:
{
"settings": {
"analysis": {
"analyzer": {
"whitespace_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"product": {
"properties": {
"product_suggestions" : {
"type" : "completion",
"index_analyzer" : "whitespace_analyzer",
"search_analyzer" : "whitespace_analyzer",
"preserve_position_increments": false,
"preserve_separators": false
}
}
}
}
}
并输入以下索引:
{
"product_suggestions" : {"input":["Apple II Lisa","Apple"]}
}
和
{
"product_suggestions" : {"input":["Iphone 5s","apple"]}
}
如果在java中我做:
SuggestRequestBuilder req = esClient.prepareSuggest("auction").addSuggestion(
new CompletionSuggestionFuzzyBuilder("searchSuggestion").field("product_suggestions").text(query).size(10));
SuggestResponse suggestResponse = req.execute().actionGet();
通过查询“app”,我将获得“apple”,“Apple”和“Apple II Lisa”。
有人知道如何解决这个问题吗?
谢谢
答案 0 :(得分:2)
我只是在其他路径中跟随...在索引之前设置小写所有单词,这样弹性搜索只会输出apple和" apple ii lisa" (我的例子)。我注意到谷歌也做了!!这也将避免更复杂的操作,并可能加快我的应用程序!!
感谢所有试图提供帮助的人。