Searching/filtering by range is a very common scenario in a real-world application. The following are a few standard cases:
Filtering by a numeric value range (such as price, size, age, and so on)
Filtering by date (for example, the events of 03/07/12 can be a range query, from 03/07/12 00:00:00 and 03/07/12 24:59:59)
Filtering by term range (for example, terms from A to D)
You need a working ElasticSearch cluster, an index named test (see Chapter 4, Basic Operations, to create an index named test), and basic knowledge of JSON.
In order to execute a range query/filter, perform the following steps:
Consider the previous example's data, which contains a
position
integer field. This can be used to execute a query in order to filter positions between 3 and 5, as follows:curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{ "query": { "filtered": { "filter": { "range" : { "position" :...