How to complete a common word from bunch of docs

Hi there,

I'm trying to use 'search_as_you_type' for auto complete. I got the idea of how this works, but stuck with a basic scneario.

for exmaple I have a field with type 'search_as_you_type'

{
  "mappings": {
    "properties": {
      "my_field": {
        "type": "search_as_you_type"
      }
    }
  }
}

and the docs are like:

{"my_field":"apple dog bob and light"}

{"my_field":"apple doll charlie "}

{"my_field":"apple doll cat"}

{"my_field":"apple donut who does not like"}

when search with "apple d", I will get all these docs returned, which is good as design.
But as auto completion, I may only want "dog", "doll" and "donut" as completion of "d".

For this case, if the result number is set to 3, then "donut" will lose.

I tries to aggregate on 'my_field._2gram' to get at least "apple dog","apple doll" and "apple donut", but seems I can not do it.

Is there any solution for such case?

Thanks.

If you are searching for a prefix based suggester, then the completion suggester might be what you are after. See Suggesters | Elasticsearch Guide [8.1] | Elastic

This query always returns whole documents and their contents, regardless of how you query.

Actually I don't want the whole content, for example I have docs with title:

final fantasy 7 remake
final cut pro
finance report and investigation 
finale inventory

When search for 'fin', I want the result to be 'final', 'finance' and 'finale.
Any idea for this scenario?
thx

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.