# What is the best way to build an auto complete

**URL:** <https://discuss.elastic.co/t/what-is-the-best-way-to-build-an-auto-complete/293829>\
**Category:** Elasticsearch\
**Created:** [January 9, 2022, 5:34pm UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-build-an-auto-complete/293829 "2022-01-09T17:34:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amir\_Faramarzi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amir_faramarzi/32/92919_2.png) [@Amir\_Faramarzi](https://discuss.elastic.co/u/Amir_Faramarzi)\
**Post date:** [January 9, 2022, 5:34pm UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-build-an-auto-complete/293829/1 "2022-01-09T17:34:24Z")

</div>

Hello friends

What is the best way to build an auto complete program in terms of performance ??

Also consider that I want to prioritize information whose names start with the text that the user is searching for.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [January 9, 2022, 10:45pm UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-build-an-auto-complete/293829/2 "2022-01-09T22:45:49Z")

</div>

Hi Amir,  
The new [terms enum api](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-terms-enum.html) may be of interest

---

<div class="post-metadata">

**Author:** ![Amir\_Faramarzi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amir_faramarzi/32/92919_2.png) [@Amir\_Faramarzi](https://discuss.elastic.co/u/Amir_Faramarzi)\
**Post date:** [January 10, 2022, 6:30am UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-build-an-auto-complete/293829/3 "2022-01-10T06:30:54Z")

</div>

Is the performance of \_terms\_enum in data around 50 GB to 100 GB or more better than ngram + wildcard or search as you type or suggesters?

And should the field type be keyword type or some other special type?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [January 10, 2022, 9:07am UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-build-an-auto-complete/293829/4 "2022-01-10T09:07:58Z")

</div>

It uses the search index directly to quickly look up values in the sorted list of unique terms held in the index. This cost can be independent of number of docs.

---

<div class="post-metadata">

**Author:** ![Amir\_Faramarzi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amir_faramarzi/32/92919_2.png) [@Amir\_Faramarzi](https://discuss.elastic.co/u/Amir_Faramarzi)\
**Post date:** [January 10, 2022, 10:43am UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-build-an-auto-complete/293829/5 "2022-01-10T10:43:36Z")

</div>

So it means it has better performance, right ??

And that given that it should only be the keyword field type

How to use the analyzer?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [January 10, 2022, 11:18am UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-build-an-auto-complete/293829/6 "2022-01-10T11:18:55Z")

</div>

We've had solutions before that use in-memory FSTs which are fast but have to be declared up-front with a special index and can cost a lot of RAM.  
The terms\_enum api is new and doesn't any required special structures. I haven't benchmarked

---

<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:** [February 7, 2022, 11:19am UTC](https://discuss.elastic.co/t/what-is-the-best-way-to-build-an-auto-complete/293829/7 "2022-02-07T11:19:55Z")

</div>

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