# Index single number as range?

**URL:** <https://discuss.elastic.co/t/index-single-number-as-range/29420>\
**Category:** Elasticsearch\
**Created:** [September 16, 2015, 3:09pm UTC](https://discuss.elastic.co/t/index-single-number-as-range/29420 "2015-09-16T15:09:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![msa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/msa/32/4817_2.png) [@msa](https://discuss.elastic.co/u/msa)\
**Post date:** [September 16, 2015, 3:09pm UTC](https://discuss.elastic.co/t/index-single-number-as-range/29420/1 "2015-09-16T15:09:23Z")

</div>

Hello,

I have an object `{ title: 'milk', weight: '3000' }`.  
I would like that search `2900` return object above. Is it possible?  
I expect that on index creation I can map weight to range `[2800..3200]`, but I can not find any things like that.

Thanks in advance,  
Sergey

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [September 16, 2015, 3:37pm UTC](https://discuss.elastic.co/t/index-single-number-as-range/29420/2 "2015-09-16T15:37:46Z")

</div>

> [@msa](#):
>
> I expect that on index creation I can map weight to range [2800..3200], but I can not find any things like that.

That is a neat idea! There isn't anything for that right now. Ranges are only a thing at query time: [Range query | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-filter.html)

If you wanted a range in the document you could make `weight` into something like `"weight": {"min": 2800, "max": 3200}` and then do a bool filter like so `"bool": {"must": [{"range": {"weight.min":{"gte":2900}}}, {"range": {"weight.max":{"lte":2900}}}]}```. I think. I've not tested it but it feels like it'd work. Be careful, though, that won't work with docs like:

```auto
{
  "foos": [
    {"weight": {"min": 2800, "max": 3200}},
    {"weight": {"min": 1800, "max": 2200}}
  ]
}

```

because filters are merged doc by doc, not object by object. You could probably work around that with `nested` but I'm not super familiar with that.

---

<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:49pm UTC](https://discuss.elastic.co/t/index-single-number-as-range/29420/3 "2017-07-05T23:49:59Z")

</div>


