# Custom Tokenizer - preserving previous tokens

**URL:** <https://discuss.elastic.co/t/custom-tokenizer-preserving-previous-tokens/32570>\
**Category:** Elasticsearch\
**Created:** [October 20, 2015, 1:15pm UTC](https://discuss.elastic.co/t/custom-tokenizer-preserving-previous-tokens/32570 "2015-10-20T13:15:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marinoc](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@marinoc](https://discuss.elastic.co/u/marinoc)\
**Post date:** [October 20, 2015, 1:15pm UTC](https://discuss.elastic.co/t/custom-tokenizer-preserving-previous-tokens/32570/1 "2015-10-20T13:15:50Z")

</div>

Does anyone know if it's possible to tokenize the following string as such?

"myField": "123-4-5678-9012-3"

I want my tokens to be:

123  
123-4  
123-4-5678  
123-4-5678-9012  
123-4-5678-9012-3

I've been playing around w the EdgeNGram and pattern tokenizers but they don't do quite what I want.

I guess my other option is to store the variations in the source prior to ingestion.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 20, 2015, 2:58pm UTC](https://discuss.elastic.co/t/custom-tokenizer-preserving-previous-tokens/32570/2 "2015-10-20T14:58:06Z")

</div>

Have you tried the [path hierarchy tokenizer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-pathhierarchy-tokenizer.html?q=hierarchy%20to)?

---

<div class="post-metadata">

**Author:** ![marinoc](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@marinoc](https://discuss.elastic.co/u/marinoc)\
**Post date:** [October 20, 2015, 3:39pm UTC](https://discuss.elastic.co/t/custom-tokenizer-preserving-previous-tokens/32570/3 "2015-10-20T15:39:21Z")

</div>

THATS IT!!

Thanks Christian

---

<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 5, 2017, 11:43pm UTC](https://discuss.elastic.co/t/custom-tokenizer-preserving-previous-tokens/32570/4 "2017-07-05T23:43:49Z")

</div>


