Reputation: 881
I have a field named search_suggest having the below
search_suggest: {
type: "completion",
analyzer: "simple",
payloads: true,
preserve_separators: false,
preserve_position_increments: false,
max_input_length: 50
}
It has values indexed as
{
input: [
"apple iphone 6"
],
output: "apple iphone 6",
weight: 5,
payload: {
category: "mobiles"
}
}
If I searched for apple ,It is giving me results. But If I search for iphone it is not giving me any results.
Is there any way in completion suggester to do this?. Do i have to index input as
I am aware of edge-ngram suggester. But the cons is it will suggest duplicates also.
Please help.
Upvotes: 3
Views: 1990
Reputation: 2327
If anyone still looking for answers,
Completion suggester is suitable for prefix matches. So, in input, you can provide the possible suffixes of your phrase. This will allow you to do prefix searches even if you start from the middle, aka sub string searches.
For example:
{
"text" : "Courtyard by Marriot Munich City",
"text_suggest" : {
"input": [
"Courtyard by Marriot Munich City",
"by Marriot Munich City",
"Marriot Munich City",
"Munich City",
"City"
],
"output" : "Courtyard by Marriot Munich City",
"weight" : 11,
"payload": { "id" : 314159 }
}
}
As you can see, wherever you start within "Courtyard by Marriot Munich City" you will get results. (Except may be for "by" because in most cases it will be discarded as a stop word).
Going up to 4-5 steps are well enough for general search strings. Also, if you handle stop-words with a filter, no need to worry about stop words in input.
Sample index analyzer
{
"settings" : {
"analysis" : {
"filter" : {
"suggester_stop" : {
"type" : "stop",
"stopwords" : "_english_",
"remove_trailing" : false,
"ignore_case" : true
},
"suggester_stemmer" : {
"type" : "stemmer",
"name" : "light_english"
}
},
"analyzer" : {
"suggester_analyzer" : {
"type" : "custom",
"tokenizer" : "standard",
"char_filter" : ["html_strip"],
"filter" : [
"standard",
"lowercase",
"suggester_stop",
"suggester_stemmer"
]
}
}
}
}
}
This will solve the problem you mentioned in one of your comments:
Then if I suggest for "apple ip", It won't give result. How about iphone 6?
{
"text_suggest" : {
"input": [
"apple iphone 6",
"iphone 6"
],
"output" : "apple iphone 6",
"weight" : 11
}
}
You will get search results for both "apple ip", "iphone 6" etc. However you will not get result for "apple 6" which is not that common for people to search anyway.
Upvotes: 7
Reputation: 1265
This should solve your problem
{
"input": [ "apple", "iphone", "6" ]
}
Upvotes: 0