Reputation: 473
I want to create search suggestions based on the tokens (and not full documents) that are present in my index.
For example: I have a simple index for movies in which I have these two documents:
{"name":"Captain America"}
{"name":"American Made"}
If I type "ame" then I should get two suggestions (as tokens)
america
american
Similarly if I type "cap" then I should get "captain" and not "Captain America"
I am having exact same problem as this post: https://discuss.elastic.co/t/elasticsearch-autocomplete-suggest-by-token/18392
I have gone through all types of suggesters and seems like they are focused on returning the whole documents rather than the tokens.
Apache Solr serves this requirement through its autosuggest functionality:
For example, if I type “kni
“ then Solr would return knives
, knife
and knit
as suggestions (based on the tokens coming from the indexed documents)
{
"responseHeader":{
"status":0,
"QTime":19},
"spellcheck":{
"suggestions":[
"kni",{
"numFound":3,
"startOffset":0,
"endOffset":3,
"suggestion":["knives",
"knife",
"knit"]}],
"collations":[
"collation","knives"]}}
One of the probable solution is mentioned in this StackOverflow thread: Elasticsearch autocomplete or autosuggest by token
But it relies on explicitly adding all the suggestions in every document. This seems to be a tedious approach.
Please let me know if this can be achieved somehow in a better way.
Thanks in advance.
Upvotes: 0
Views: 400
Reputation: 8658
It wont return the part like America when you search as "ame" because its stored as "Captain America". You get the original text which is stored
You need to store it as only America.
In your case you the the field name has value "Captain America". If you are applying the text field type for it, it may be creating tokens for you like Captain, America etc.
These are the token created at the time of indexing and created to help you in search/auto suggest.
As a response of search or autosuggest you will get the original text.
Although the alternative way is to highlight the matching term or part of the term from the response of original text of the autosuggest.
Upvotes: 1