Query whether an integer is within a range of field values

I have an index where documents contain two fields that together make up a range, ie:

    "office_postal_from" : [
    "office_postal_to" : [

(See this gist for a complete example)

So in the case above, there are 3 ranges: 1500-1799, 1800-1999, 2000-2000 (disregard the obvious case for improving the range data here).

How can I query ES with the question: "give me all documents in which the postal code 1650 is within a range in the document" - and then receive the above document as one of the results?

I'm not very proficient with ES, but I have looked around quite a bit now, and have been entirely unable to get ideas on how to achieve this.

I'm using ES 5.2 btw.

What about this? https://www.elastic.co/guide/en/elasticsearch/reference/6.3/range.html

@dadoonet Thanks - I will have a look at range types (again).

Just so I understand you - are you suggesting that I change the field datatype to integer_range so that I can do a term query with the value? The indexed data is actually coming from a CMS, so I was hoping to avoid that approach, but I can see that range types do in fact seem to fit the bill.

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