I am using Elastic search's Completion suggester for one of our Auto Complete text box. I was wondering whether it is possible to return the Documents instead of the strings (Suggestion) using the Completion suggester ?
For eg. Now If i search for "Ban" it will return "Banana", "Bandana". Just the string but is it possible to return the complete document which the string is part of ?
If I wrote normal full text queries on the same field will that be optimized for AutoComplete ?
When I tried running the raw Elastic search completion query. I was getting the complete document instead of suggested strings -
Doc Link : https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html#querying
Query I have used -
POST /my_entities/_search?pretty
{
"suggest": {
"auto-suggest" : {
"prefix" : "banda",
"completion" : {
"field" : "name"
}
}
}
}.
Above raw query returned the following source (Only pasting the source of the ouput)-
{
"_source":{
"entityType":"cloth",
"entityId":"bandana",
"name":"Bandana",
}
}
Completion suggester will not return the whole document as its just a suggester and doesn't work like full-text search which returns the whole document.
Completion suggester will return the whole document as part of the suggest. You can control which all keys to be returned using the source in while querying.
Refer this link for information on how to extract the source fields using Java Client API.
If you want the whole document, then you implement autosuggest in full-text and there are various ways.
You can also refer https://stackoverflow.com/a/60584211/4039431 for more information on the functional and non-functional requirements to build autocomplete.