# Ngrams - choosing the value of N

**URL:** <https://discuss.elastic.co/t/ngrams-choosing-the-value-of-n/228096>\
**Category:** Elasticsearch\
**Created:** [April 15, 2020, 11:11am UTC](https://discuss.elastic.co/t/ngrams-choosing-the-value-of-n/228096 "2020-04-15T11:11:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vibhuti\_sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vibhuti_sharma/32/49541_2.png) [@vibhuti\_sharma](https://discuss.elastic.co/u/vibhuti_sharma)\
**Post date:** [April 15, 2020, 11:11am UTC](https://discuss.elastic.co/t/ngrams-choosing-the-value-of-n/228096/1 "2020-04-15T11:11:38Z")

</div>

I need to perform substring search on the content of files. I decided to go with the NGrams approach - index the entire content of all the files as ngrams (I am using an ngram tokenizer) and then query them using a match phrase query. So, if I index using n=3, then search text "client" would look for a document containing cli, ien, ent in that order.  
I understand that indexing ngrams will definitely lead to an increase in index size, but my concern now is to choose a value of n which leads to the _lowest possible increase_ in index size.  
Intuitively when I think of it, n=1 or n=2 would form the least possible number of grams. False matches are not a concern for me since running a match phrase query takes care of that. What would be the drawbacks of picking a very low value of n?

---

<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:** [May 13, 2020, 11:11am UTC](https://discuss.elastic.co/t/ngrams-choosing-the-value-of-n/228096/2 "2020-05-13T11:11:42Z")

</div>

Closed on May 13, 2020, 11:11am UTC

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