Reputation: 1040
I'm doing an auto-complete in java using elasticsearch, so for that I built and map with the following code:
{
"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
}
}
}
}
}
And put the following index:
{
"product_suggestions" : {"input":["Apple II Lisa","Apple"]}
}
and
{
"product_suggestions" : {"input":["Iphone 5s","apple"]}
}
If in java I do:
SuggestRequestBuilder req = esClient.prepareSuggest("auction").addSuggestion(
new CompletionSuggestionFuzzyBuilder("searchSuggestion").field("product_suggestions").text(query).size(10));
SuggestResponse suggestResponse = req.execute().actionGet();
With the query "app" I will get "apple","Apple" and "Apple II Lisa".
Someone knows how I can fix this?
Thanks
Upvotes: 3
Views: 1828
Reputation: 1040
I just followed in other path... set lowercase all words before indexing and this way the elasticsearch will only output apple and "apple ii lisa" (the ones of my example). I notice that is what google does also!! This will also avoid more complicated operations and maybe speedup my app!!
Thank you to everyone who tried to help.
Upvotes: 3