Simple filter of value against range-type field


(David Kemp) #1

It's nice to see that there is now a "range" data type:
https://www.elastic.co/guide/en/elasticsearch/reference/current/range.html

The example only shows how to do a range query against a range field.
Is there a way to do a simple term query against a range field?
i.e. a way to find documents for which a specified value falls within the range?

I was hoping that I could do this, but it does not work:

DELETE /foo

PUT /foo
{
  "mappings": {
    "foo": {
      "properties": {
        "myrange": {"type": "integer_range"}
      }
    }
  }
}

POST /foo/foo
{
  "myrange": {
    "gte": 10,
    "lte": 20
  }
}

POST /foo/foo
{
  "myrange": {
    "gte": 20,
    "lte": 30
  }
}

GET /foo/foo/_search
{
  "query": {
    "term": {
      "myrange": {
        "value": 15
      }
    }
  }
}

The query fails with:

Field [myrange] of type [integer_range] does not support range queries


(Bryan) #2

I believe what you're attempting to do worked in previous versions and broke in 5.5.0.

Until recently I could do:

{"query": {"terms": {"myrange": [72058095486370049, 72058095486370203]}}}

With mappings:

"myrange" : { "type" : "long_range" },

But in 5.5.0 I get:

  "caused_by" : {
    "type" : "illegal_argument_exception",
    "reason" : "Field [myrange] of type [long_range] does not support range queries"
  }

(Bryan) #3

I verified this also does not work in 5.4.3 but does work in 5.2.2.


(Bryan) #4

This also works in 5.3.0.

I'm currently guessing it changed with this commit:

And related to Lucene changes with:

https://issues.apache.org/jira/browse/LUCENE-7624


(Bryan) #5

We pushed a fix.


(system) #6

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