Executing the histogram aggregation
ElasticSearch numerical values can be used to process histogram data. The histogram representation is a very powerful way to show data to end users.
Getting ready
You need a working ElasticSearch cluster and an index populated with the script (chapter_06/executing_histogram_aggregations.sh
) available at https://github.com/aparo/elasticsearch-cookbook-second-edition.
How to do it...
Using the items populated with the script, we want to calculate aggregations on:
Age with an interval of 5 years
Price with an interval of 10$
Date with an interval of 6 months
To execute histogram aggregations, we will perform the steps given as follows:
The query will be as follows:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true&size=0' -d '{ "query": { "match_all": {} }, "aggregations": { "age" : { "histogram" : { "field" : "age", "interval" : 5 } }, "price" : { "histogram" : { "field" ...