# Indexing a numeric range field

**URL:** <https://discuss.elastic.co/t/indexing-a-numeric-range-field/14836>\
**Category:** Elasticsearch\
**Created:** [December 12, 2013, 12:34pm UTC](https://discuss.elastic.co/t/indexing-a-numeric-range-field/14836 "2013-12-12T12:34:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sander\_Toonen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sander_toonen/32/1913_2.png) [@Sander\_Toonen](https://discuss.elastic.co/u/Sander_Toonen)\
**Post date:** [December 12, 2013, 12:34pm UTC](https://discuss.elastic.co/t/indexing-a-numeric-range-field/14836/1 "2013-12-12T12:34:23Z")

</div>

Hi!

I'm am looking for a way to _index_ documents which contain numeric ranges.  
E.g:

{

> ```
> name: Document A
> size: 100-200
> 
> ```
> 
> }  
> {  
> name: Document B  
> size: 190-240  
> }  
> {  
> name: Document C  
> size: 230  
> }

I need to be able to query for a range so that all documents that have an  
overlapping range will be returned:

195-220 should return A and B  
230-235 should return B and C

I currently do not know of a way to index a range, only how to query for a  
range.  
Is anybody aware of a way to achieve this?

Thanks in advance!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1e3dda92-063b-4291-946c-45d1821ea511%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1e3dda92-063b-4291-946c-45d1821ea511%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Andrew\_Cholakian\_2](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@Andrew\_Cholakian\_2](https://discuss.elastic.co/u/Andrew_Cholakian_2)\
**Post date:** [December 13, 2013, 5:06am UTC](https://discuss.elastic.co/t/indexing-a-numeric-range-field/14836/2 "2013-12-13T05:06:10Z")

</div>

You cannot index a range, but then you don't need to. You should look at  
storing the range as two values, a range\_floor, and a range\_ceil. Then you  
can use standard range filters in conjunction with a 'and' filter to find  
what you're looking for. Be sure to read this blog post about caching  
behavior and filters when used with ranges  
([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/)).

* * *

Andrew Cholakian  
Developer, Found Hosted Elasticsearch  
www.found.no, @foundsays

On Thursday, December 12, 2013 4:34:23 AM UTC-8, Sander Toonen wrote:

> Hi!
> 
> I'm am looking for a way to _index_ documents which contain numeric  
> ranges. E.g:
> 
> {
> 
> > ```
> > name: Document A
> > size: 100-200
> > 
> > ```
> > 
> > }  
> > {  
> > name: Document B  
> > size: 190-240  
> > }  
> > {  
> > name: Document C  
> > size: 230  
> > }
> 
> I need to be able to query for a range so that all documents that have an  
> overlapping range will be returned:
> 
> 195-220 should return A and B  
> 230-235 should return B and C
> 
> I currently do not know of a way to index a range, only how to query for a  
> range.  
> Is anybody aware of a way to achieve this?
> 
> Thanks in advance!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e397b833-68dd-444e-9b29-bc13ad92995a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e397b833-68dd-444e-9b29-bc13ad92995a%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:01am UTC](https://discuss.elastic.co/t/indexing-a-numeric-range-field/14836/3 "2017-07-06T02:01:31Z")

</div>


