Aggregations on numeric values (range, histogram)

Just like date range aggregation, range aggregation is used to define buckets based on the ranges specified. In the following example, we will use range aggregation to group the products based on the number of products sold. The query is as follows:

 #Aggs bases on Filters POST chapter8/_search {   "size": 0,   "aggs": {     "price_range": {       "range": {         "field": "products_sold",         "ranges": [           {             "to": "10"           },           {             "from": "10",             "to": "20"           },           {             "from": "20"           }         ]       }     }   } }

The response is as follows:

{   ....   "hits": {     "total": 5,     "max_score": 0,     "hits": []   },   "aggregations": {     "price_range": {       "buckets": [         {           "key": "*-10.0",           "to": 10,           "doc_count": 0         },         {           "key": "10.0-20.0",           "from": 10,           "to": 20, "doc_count": ...

Get Learning Elasticsearch 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.