# Query Results for "ngram" search

**URL:** https://discuss.elastic.co/t/query-results-for-ngram-search/66304
**Category:** Elasticsearch
**Created:** [November 16, 2016, 9:05pm UTC](https://discuss.elastic.co/t/query-results-for-ngram-search/66304 "2016-11-16T21:05:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Stefan2](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@Stefan2](https://discuss.elastic.co/u/Stefan2)
#### Post date: [November 16, 2016, 9:05pm UTC](https://discuss.elastic.co/t/query-results-for-ngram-search/66304/1 "2016-11-16T21:05:31Z")

</div>

We created a "ngram index" and search works fine. However, returning results are not what we want to have.

In case we do have the following words in our index:  
this  
test  
tests  
the index

and I search for "th" I´d like to get a result list  
this  
the text

Means the beginning of the matches (this is for autocomplete). I tried it with "highlight" but I always get more parts of the document (not only the words starting with "th").

How can I tell ElasticSearch to get a search result which contains the "autocomplete" words?

Thank you.

---

<div class="post-metadata">

### Author: ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)
#### Post date: [November 17, 2016, 9:33pm UTC](https://discuss.elastic.co/t/query-results-for-ngram-search/66304/2 "2016-11-17T21:33:39Z")

</div>

Take a look at the [`edge_ngram` tokenizer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenizer.html) or the [`edgeNGram` token filter](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenfilter.html), rather than the regular ngram tokenizer/token filter. These will only generate ngrams from the start of the words.

If you're doing autocomplete, have you considered using the [Completion Suggester](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html) instead?

---

<div class="post-metadata">

### Author: ![Stefan2](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@Stefan2](https://discuss.elastic.co/u/Stefan2)
#### Post date: [November 24, 2016, 7:53am UTC](https://discuss.elastic.co/t/query-results-for-ngram-search/66304/3 "2016-11-24T07:53:35Z")

</div>

Hello, thank you for this fast response. This works for us (the edge\_ngram tokenizer).

---

<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: [December 22, 2016, 7:53am UTC](https://discuss.elastic.co/t/query-results-for-ngram-search/66304/4 "2016-12-22T07:53:35Z")

</div>

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