# Auto Complete and search user supplied text/phrase

**URL:** <https://discuss.elastic.co/t/auto-complete-and-search-user-supplied-text-phrase/5327>\
**Category:** Elasticsearch\
**Created:** [September 7, 2011, 4:35pm UTC](https://discuss.elastic.co/t/auto-complete-and-search-user-supplied-text-phrase/5327 "2011-09-07T16:35:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nchandra](https://avatars.discourse-cdn.com/v4/letter/n/bb73d2/32.png) [@nchandra](https://discuss.elastic.co/u/nchandra)\
**Post date:** [September 7, 2011, 4:35pm UTC](https://discuss.elastic.co/t/auto-complete-and-search-user-supplied-text-phrase/5327/1 "2011-09-07T16:35:18Z")

</div>

Hi,

I have a collection of product data (cameras) that I am indexing.  
Users can search a product by providing a phrase and I want to enable  
'auto complete' or 'auto suggestions' feature.

Being new to search domain, what query types are recommended for these  
2 use cases?

Currently, I am inclined towards textPhrasePrefixQuery for 'auto  
suggestions' and text query for user provided search string.

Nishant

---

<div class="post-metadata">

**Author:** ![freddj](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@freddj](https://discuss.elastic.co/u/freddj)\
**Post date:** [September 13, 2011, 3:59pm UTC](https://discuss.elastic.co/t/auto-complete-and-search-user-supplied-text-phrase/5327/2 "2011-09-13T15:59:27Z")

</div>

Hi

I'm also implementing an 'autocomplete' feature and I'm not very experienced  
in that area.  
textPhrasePrefixQuery is a good starting point, but I dropped it for  
several reasons:

- ranking is a bit strange
- That looked a bit slow to run (but I did not make a scientific  
evaluation of that).
- if the prefix is too short, it can fail.
- If you look for 'fo ba', it will miss 'foo bar'

Internally, it generates a lot of sub queries (one for every token in the  
index that has the same prefix) and I suppose it does some kind of a massive  
OR or dismax between them (that explains the problem I had).

So instead, I choose to index my field with an NGram token filter and I just  
do a regular 'text' query on it. I'm happy with the results for now

---

<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:** [July 6, 2017, 3:54am UTC](https://discuss.elastic.co/t/auto-complete-and-search-user-supplied-text-phrase/5327/3 "2017-07-06T03:54:30Z")

</div>


