Best way to search for number ranges in text

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?

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