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.

Average aggregations

The avg metric is a single-value metric aggregations that returns the average value of a field.

The following example calculates the average of the taxful_total_price field:

  1. GET opensearch_dashboards_sample_data_ecommerce/_search
  2. {
  3. "size": 0,
  4. "aggs": {
  5. "avg_taxful_total_price": {
  6. "avg": {
  7. "field": "taxful_total_price"
  8. }
  9. }
  10. }
  11. }

copy

Example response

  1. {
  2. "took": 85,
  3. "timed_out": false,
  4. "_shards": {
  5. "total": 1,
  6. "successful": 1,
  7. "skipped": 0,
  8. "failed": 0
  9. },
  10. "hits": {
  11. "total": {
  12. "value": 4675,
  13. "relation": "eq"
  14. },
  15. "max_score": null,
  16. "hits": []
  17. },
  18. "aggregations": {
  19. "sum_taxful_total_price": {
  20. "value": 75.05542864304813
  21. }
  22. }
  23. }