# Store multiple ranges (of integer values) in the same field

**URL:** <https://discuss.elastic.co/t/store-multiple-ranges-of-integer-values-in-the-same-field/154448>\
**Category:** Elasticsearch\
**Created:** [October 29, 2018, 1:36pm UTC](https://discuss.elastic.co/t/store-multiple-ranges-of-integer-values-in-the-same-field/154448 "2018-10-29T13:36:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elastic\_guy](https://avatars.discourse-cdn.com/v4/letter/e/ecb155/32.png) [@elastic\_guy](https://discuss.elastic.co/u/elastic_guy)\
**Post date:** [October 29, 2018, 1:36pm UTC](https://discuss.elastic.co/t/store-multiple-ranges-of-integer-values-in-the-same-field/154448/1 "2018-10-29T13:36:32Z")

</div>

Hi,  
I am interested with the best way of storing multiple ranges in the same field (or any other better way for storing multiple ranges).

for example,  
I have an object type A, that should hold the following data:

> A:
> 
> - name
> - RangesFieldA: [1-2, 5, 7, 22-29]
> - RangedFieldB: [2, 4-6].

then, I would like to query the objects of type A, by asking - give me all the objects of type A that range (x-y) contained in 'RangesFieldA' field.

now, I saw that there exist a range type, but I couldn't find if it's support multiple ranges?

> **[Range datatypes | Elasticsearch Reference \[5.6\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/range.html)**

I am currently using ES 5.6, and in the near future, we are upgrading to 6+ if it matters..

I am also interested to know, if your answer changes if A is a nested object inside another document..

Thanks

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [October 29, 2018, 4:25pm UTC](https://discuss.elastic.co/t/store-multiple-ranges-of-integer-values-in-the-same-field/154448/2 "2018-10-29T16:25:44Z")

</div>

Yes, this is possible (at least in 6.x but I believe that is as well possible in your version), you just need to send your ranges as an array, for example:

```auto
PUT range_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "int_range": {
          "type": "integer_range"
        }
      }
    }
  }
}

PUT range_index/_doc/1
{
  "int_range" : [{ 
    "gte" : 10,
    "lte" : 20
  },
  { 
    "gte" : 30,
    "lte" : 40
  }]
}

```

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [October 29, 2018, 4:26pm UTC](https://discuss.elastic.co/t/store-multiple-ranges-of-integer-values-in-the-same-field/154448/3 "2018-10-29T16:26:25Z")

</div>

And it should apply to nested field as well.

---

<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 26, 2018, 4:29pm UTC](https://discuss.elastic.co/t/store-multiple-ranges-of-integer-values-in-the-same-field/154448/4 "2018-11-26T16:29:58Z")

</div>

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