# Range query on integer fields

**URL:** <https://discuss.elastic.co/t/range-query-on-integer-fields/261089>\
**Category:** Elasticsearch\
**Created:** [January 14, 2021, 8:06am UTC](https://discuss.elastic.co/t/range-query-on-integer-fields/261089 "2021-01-14T08:06:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jogi\_Michal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jogi_michal/32/45613_2.png) [@Jogi\_Michal](https://discuss.elastic.co/u/Jogi_Michal)\
**Post date:** [January 14, 2021, 8:06am UTC](https://discuss.elastic.co/t/range-query-on-integer-fields/261089/1 "2021-01-14T08:06:43Z")

</div>

Hi all,

My mapping:

```auto
    {
        'doc': {
            'sources': {
                'properties': {
                     'depth': {
                         'type': 'integer'
                     }
                }
            }
        }
    }

```

I have docs like:

```auto
    {'sources': [{'depth': 0}, {'depth': 3}]}
    {'sources': [{'depth': 3}]}

```

My query:

```auto
    {
       "query": {
          "range": {
             "sources.depth": {
                "gt": 2
             }
          }
       }
    }

```

returns above 2 documents which is expected.

But, how should I create a query to return only the second one?  
I mean is there some kind of mechanism in ES query that will return me the result of such conditions?

```auto
    {
       "query": {
          "must": {
              "range": {
                 "sources.depth": {
                    "gt": 2
                 }
             }
         },
          "must_not": {
              "range": {
                 "sources.depth": {
                    "lte": 2
                 }
             }
          }
       }
    }

```

---

<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:** [February 11, 2021, 8:06am UTC](https://discuss.elastic.co/t/range-query-on-integer-fields/261089/2 "2021-02-11T08:06:48Z")

</div>

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