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

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"
  }
}
  ]
}

Could you provide a full recreation script as described in About the Elasticsearch category. 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.

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

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

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.

As described in About the Elasticsearch category:

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

Updated the question. Thanks.

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

How am I supposed to reproduce your problem?

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