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


(Ankur Lathwal) #1

I am using elastic search 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"
  }
}
  ]
}

(David Pilato) #2

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.


(Ankur Lathwal) #3

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


(David Pilato) #4

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


(Ankur Lathwal) #5

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.


(David Pilato) #6

As described in About the Elasticsearch category:

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

(Ankur Lathwal) #7

Updated the question. Thanks.


(David Pilato) #8

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

How am I supposed to reproduce your problem?


(system) #9

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