1

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",
   }
} 
ted
  • 3,911
  • 3
  • 26
  • 49
  • 1
    I was reading through the blog provided in the answer.. I thought I will keep the question open for 1-2 days possibly if any other answer come in or some upvote for your answer to confirm your first statment (About suggester cant work with whole document), or a link to some trusted sources. I have upvoted the answer already, thanks for your answer :) – ted Jun 02 '20 at 19:12
  • 1
    It looks like elastic search return the complete document if we dint specify the source field. it works similar to hits. – ted Jun 04 '20 at 10:31
  • thats a great news, i wanted to try it myself but didn't get time(sorry for that), would like to update my answer with this caveat. If you don't mind can you edit my answer and add this information as you can do this better with me :) .. would love to try it soon. – Amit Jun 04 '20 at 10:48

1 Answers1

1

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Amit
  • 30,756
  • 6
  • 57
  • 88
  • `POST /my_entities/_search?pretty { "suggest": { "auto-suggest" : { "prefix" : "swiggy", "completion" : { "field" : "entityName" } } } }` in the example Elastic search documentation a similar query is returning an array of string in the source, under key suggest. But when I tried running the query It is returning the complete document instead of an array of strings. So Do suggest return the complete document ? I was trying with Java API earlier with raw query it's returning complete document. – ted Jun 03 '20 at 10:58
  • @ted can you share the elasticsearch doc link and provide all the steps to reproduce it, in comments its difficult, maybe you can update this information in your question. – Amit Jun 03 '20 at 11:01