Reputation: 21509
I've got a working version of autocomplete for elastic search. One issue though, is if I search for xbox 360. I get xbox 360 and xbox one coming back as possible suggestions.
I'd like for suggestions to only consider suggestions which contain the whole query up until that point of suggestion. For example if I type xbox 3, elastic search should never return xbox one, but only xbox 360.
My query is running against the _suggestions end point. My config is as follows.
{
"mappings": {
"query" : {
"properties" : {
"product" : { "type" : "string" },
"name_suggest" : {
"type" : "completion"
}
}
}
Upvotes: 0
Views: 563
Reputation: 4733
I think you are describing the completion suggester. If that is the case, you can use this as an example:
PUT /mymusicsuggest
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"album": {
"properties": {
"name": {
"type": "string"
},
"suggest": {
"type": "completion",
"index_analyzer": "simple",
"search_analyzer": "simple",
"payloads": true
}
}
}
}
}
PUT /mymusicsuggest/album/1
{
"name" : "Tori Amos - Little Earthquakes",
"suggest" : {
"input": [ "earthquakes", "little", "tori", "amos" ],
"output": "Tori Amos - Little Earthquakes",
"payload" : { "songs" : ["11861","11839","11849","11853","11841", "11847","11851","11845","11855","11843","11859","11857"] },
"weight" : 10
}
}
Upvotes: 1