# Best way to search for number ranges in text

**URL:** <https://discuss.elastic.co/t/best-way-to-search-for-number-ranges-in-text/103010>\
**Category:** Elasticsearch\
**Created:** [October 6, 2017, 1:15pm UTC](https://discuss.elastic.co/t/best-way-to-search-for-number-ranges-in-text/103010 "2017-10-06T13:15:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![carasel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carasel/32/51435_2.png) [@carasel](https://discuss.elastic.co/u/carasel)\
**Post date:** [October 6, 2017, 1:15pm UTC](https://discuss.elastic.co/t/best-way-to-search-for-number-ranges-in-text/103010/1 "2017-10-06T13:15:03Z")

</div>

I have a field which contains a text description of a special offer, e.g. "get 10% off when you spend over $50 on this product!"

I want to be able to search for documents where this field contains a number range "% off" e.g. documents containing between "5% off" and "10% off".

My ideas so far are to use a pattern replace char filter to replace all numeric characters not followed by "% off", then all non-numeric characters. I think this should get me the number before a % symbol. Then I could do a range query on that subfield.

Another option would be to use a custom analyzer, not stripping %, using a whitespace tokenizer. Then query for "5% off" OR "6% off"... etc using a phrase match query.

I'm new to elasticsearch, so I thought it quite likely that I am missing a better way to do this. Any suggestions?

---

<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:** [November 3, 2017, 1:15pm UTC](https://discuss.elastic.co/t/best-way-to-search-for-number-ranges-in-text/103010/2 "2017-11-03T13:15:20Z")

</div>

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