This version of the OpenSearch documentation is no longer maintained. For the latest version, see the current documentation. For information about OpenSearch version maintenance, see Release Schedule and Maintenance Policy.

Range aggregations

The range aggregation lets you define the range for each bucket.

For example, you can find the number of bytes between 1000 and 2000, 2000 and 3000, and 3000 and 4000. Within the range parameter, you can define ranges as objects of an array.

  1. GET opensearch_dashboards_sample_data_logs/_search
  2. {
  3. "size": 0,
  4. "aggs": {
  5. "number_of_bytes_distribution": {
  6. "range": {
  7. "field": "bytes",
  8. "ranges": [
  9. {
  10. "from": 1000,
  11. "to": 2000
  12. },
  13. {
  14. "from": 2000,
  15. "to": 3000
  16. },
  17. {
  18. "from": 3000,
  19. "to": 4000
  20. }
  21. ]
  22. }
  23. }
  24. }
  25. }

copy

The response includes the from key values and excludes the to key values:

Example response

  1. ...
  2. "aggregations" : {
  3. "number_of_bytes_distribution" : {
  4. "buckets" : [
  5. {
  6. "key" : "1000.0-2000.0",
  7. "from" : 1000.0,
  8. "to" : 2000.0,
  9. "doc_count" : 805
  10. },
  11. {
  12. "key" : "2000.0-3000.0",
  13. "from" : 2000.0,
  14. "to" : 3000.0,
  15. "doc_count" : 1369
  16. },
  17. {
  18. "key" : "3000.0-4000.0",
  19. "from" : 3000.0,
  20. "to" : 4000.0,
  21. "doc_count" : 1422
  22. }
  23. ]
  24. }
  25. }
  26. }