Executing the range aggregation
The previous recipe describes an aggregation type that can be very useful if a bucket must be computed on terms or on a limited number of items. Otherwise, it's often required to return the buckets that are aggregated in ranges—the range aggregation answers this requirement. The commons scenarios in which this aggregation can be used are:
Price ranges (used in shops)
Size ranges
Alphabetical ranges
Getting ready
You need a working ElasticSearch cluster and an index populated with the script (chapter_06/executing_range_aggregations.sh
) available at https://github.com/aparo/elasticsearch-cookbook-second-edition.
How to do it...
To execute range aggregations, we will perform the steps given as follows:
We want to provide three types of aggregation ranges, as follows:
Price aggregation: This method aggregates the price of the items in a range
Age aggregation: This method aggregates the age contained in a document in four ranges of 25 years
Date aggregation: This method aggregates...