# Range filter not working for “gt” operator but working for “lt”

**URL:** <https://discuss.elastic.co/t/range-filter-not-working-for-gt-operator-but-working-for-lt/135603>\
**Category:** Elasticsearch\
**Created:** [June 12, 2018, 9:33pm UTC](https://discuss.elastic.co/t/range-filter-not-working-for-gt-operator-but-working-for-lt/135603 "2018-06-12T21:33:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankurlathwal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankurlathwal/32/35879_2.png) [@ankurlathwal](https://discuss.elastic.co/u/ankurlathwal)\
**Post date:** [June 12, 2018, 9:33pm UTC](https://discuss.elastic.co/t/range-filter-not-working-for-gt-operator-but-working-for-lt/135603/1 "2018-06-12T21:33:10Z")

</div>

I am using Elasticsearch to index my documents and wanted to filter documents based on a specific property. Here is my code:

> filter.push({  
> range: {"audience.ethnicity.asian" : { gt: 50 } }  
> })

It doesn't work with gt operator (sends back results that are not consistent) but works with lt operator

> filter.push({  
> range: {"audience.ethnicity.asian" : { lt: 50 } }  
> })

This works surprisingly. I have double checked that the property value IS an integer. I have tried many different ways but can't seem to figure out what am I missing.

Here is the query from Kibana

```
GET opensponsorship/_search
{
  "query": {
"bool": {
  "filter": [
    {
      "term": {
        "isPublic": true
      }
    },
    {
      "term": {
        "isDeleted": false
      }
    },
    {
			    "range": {
			      "audience.ethnicity.asian" : {"gt": 50}
			    }
    }
  ]
}
  },
  "size": "60",
  "from": 0,
  "sort": [
{
  "followers": {
    "order": "desc"
  }
}
  ]
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 13, 2018, 2:40am UTC](https://discuss.elastic.co/t/range-filter-not-working-for-gt-operator-but-working-for-lt/135603/2 "2018-06-13T02:40:41Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![ankurlathwal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankurlathwal/32/35879_2.png) [@ankurlathwal](https://discuss.elastic.co/u/ankurlathwal)\
**Post date:** [June 13, 2018, 2:04pm UTC](https://discuss.elastic.co/t/range-filter-not-working-for-gt-operator-but-working-for-lt/135603/3 "2018-06-13T14:04:15Z")

</div>

Thanks for pointing it out. I have pasted my query from Kibana in the original post.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 13, 2018, 3:08pm UTC](https://discuss.elastic.co/t/range-filter-not-working-for-gt-operator-but-working-for-lt/135603/4 "2018-06-13T15:08:04Z")

</div>

I can not reproduce with this. You need to add a complete script I can run otherwise it's kind of useless. Thanks

---

<div class="post-metadata">

**Author:** ![ankurlathwal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankurlathwal/32/35879_2.png) [@ankurlathwal](https://discuss.elastic.co/u/ankurlathwal)\
**Post date:** [June 13, 2018, 3:21pm UTC](https://discuss.elastic.co/t/range-filter-not-working-for-gt-operator-but-working-for-lt/135603/5 "2018-06-13T15:21:10Z")

</div>

Sorry I have limited knowledge of elastic search. But I read the link your provided and copied the query that I do in Kibana. Can you please explain what you mean by complete script? Thanks.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 13, 2018, 3:36pm UTC](https://discuss.elastic.co/t/range-filter-not-working-for-gt-operator-but-working-for-lt/135603/6 "2018-06-13T15:36:21Z")

</div>

As described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21):

```auto
DELETE index
PUT index/_doc/1
{
  "foo": "bar"
}
GET index/_search
{
  "query": {
    "match": {
      "foo": "bar"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![ankurlathwal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankurlathwal/32/35879_2.png) [@ankurlathwal](https://discuss.elastic.co/u/ankurlathwal)\
**Post date:** [June 13, 2018, 3:48pm UTC](https://discuss.elastic.co/t/range-filter-not-working-for-gt-operator-but-working-for-lt/135603/7 "2018-06-13T15:48:21Z")

</div>

Updated the question. Thanks.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 13, 2018, 4:03pm UTC](https://discuss.elastic.co/t/range-filter-not-working-for-gt-operator-but-working-for-lt/135603/8 "2018-06-13T16:03:07Z")

</div>

Not sure you did. I mean you just added the indexname.

How am I supposed to reproduce your problem?

---

<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 11, 2018, 4:03pm UTC](https://discuss.elastic.co/t/range-filter-not-working-for-gt-operator-but-working-for-lt/135603/9 "2018-07-11T16:03:21Z")

</div>

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