I want to implement autocomplete feature in ES I have followed this tutorial from ES documentations
my Indexing is:
{
"properties" : {
"suggest" : {
"type" : "completion"
},
"titleKeyword" : {
"type": "keyword"
}
}
}
}
I am putting text value in titleKeyword
field
then I queried like follows
{
"suggest" : {
"my-suggestion" : {
"text" : "iphone",
"term" : {
"field" : "titleKeyword"
}
}
}
}
The result is:
...
"suggest": {
"my-suggestion": [
{
"text": "iphone",
"offset": 0,
"length": 6,
"options": []
}
]
}
expected result is
options:[iphone x, iphone 11, iphone 11 pro, iphone 7]
Note: titles are complete sentences like "iPhone x 64gb black"
as far as I understood from the documentation that I have to give the suggestions in "advance" when creating the document which is impossible in my case is there any way to implement this feature without putting suggestions manually?
Thanks
For this simple requirement, no need to use the Elasticsearch suggestor which is difficult to understand and some part of it is still under development, More info on blog and what all to take care when building advance autocomplete is in my this SO answer.
Coming to your requirements which can be easily solved using the
text
field(looks like you are usingkeyword
type) and simple match query as shown below:Index Def
Index all 4 types of
iphone
Search query (
iphone
will bring all four docs)Search result