# How to complete a common word from bunch of docs

**URL:** <https://discuss.elastic.co/t/how-to-complete-a-common-word-from-bunch-of-docs/300549>\
**Category:** Elasticsearch\
**Created:** [March 24, 2022, 9:33am UTC](https://discuss.elastic.co/t/how-to-complete-a-common-word-from-bunch-of-docs/300549 "2022-03-24T09:33:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casparxu](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@casparxu](https://discuss.elastic.co/u/casparxu)\
**Post date:** [March 24, 2022, 9:33am UTC](https://discuss.elastic.co/t/how-to-complete-a-common-word-from-bunch-of-docs/300549/1 "2022-03-24T09:33:30Z")

</div>

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'

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

```

and the docs are like:

```auto
{"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.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 24, 2022, 1:15pm UTC](https://discuss.elastic.co/t/how-to-complete-a-common-word-from-bunch-of-docs/300549/2 "2022-03-24T13:15:46Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/8.1/search-suggesters.html#completion-suggester)

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

---

<div class="post-metadata">

**Author:** ![CHU\_XU](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chu_xu/32/45946_2.png) [@CHU\_XU](https://discuss.elastic.co/u/CHU_XU)\
**Post date:** [March 25, 2022, 2:47am UTC](https://discuss.elastic.co/t/how-to-complete-a-common-word-from-bunch-of-docs/300549/3 "2022-03-25T02:47:12Z")

</div>

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

```json
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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 22, 2022, 2:47am UTC](https://discuss.elastic.co/t/how-to-complete-a-common-word-from-bunch-of-docs/300549/4 "2022-04-22T02:47:47Z")

</div>

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