# Limit ngram based on the token

**URL:** <https://discuss.elastic.co/t/limit-ngram-based-on-the-token/74407>\
**Category:** Elasticsearch\
**Created:** [February 8, 2017, 4:16pm UTC](https://discuss.elastic.co/t/limit-ngram-based-on-the-token/74407 "2017-02-08T16:16:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkata\_sreekanth\_bh](https://avatars.discourse-cdn.com/v4/letter/v/65b543/32.png) [@venkata\_sreekanth\_bh](https://discuss.elastic.co/u/venkata_sreekanth_bh)\
**Post date:** [February 8, 2017, 4:16pm UTC](https://discuss.elastic.co/t/limit-ngram-based-on-the-token/74407/1 "2017-02-08T16:16:53Z")

</div>

Is it possible to limit ngram to generate ngrams only for the first two or three characters. more like a traveling edge ngram.  
The min and max ngram would not be the same values as I want it to behave like edge ngram.

The reason I am doing this is I would to have substring search like say "234567" and 123456789 should appear.

note: in the real world the tokens are alphanumeric and substring search is on keyword

ex:

123456789

I would like edge ngrams for 123456789  
23456789, 3456789.

limiting ngram to first 3 characters.

current ngram config

"ngram\_filter": {  
"type": "nGram",  
"min\_gram": 2,  
"max\_gram": 500  
}

---

<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:** [March 8, 2017, 4:17pm UTC](https://discuss.elastic.co/t/limit-ngram-based-on-the-token/74407/2 "2017-03-08T16:17:09Z")

</div>

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