Using a range query/filter

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)

Getting ready

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.

How to do it...

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 ...

Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.