Global aggregations

The global aggregations lets you break out of the aggregation context of a filter aggregation. Even if you have included a filter query that narrows down a set of documents, the global aggregation aggregates on all documents as if the filter query wasn’t there. It ignores the filter aggregation and implicitly assumes the match_all query.

The following example returns the avg value of the taxful_total_price field from all documents in the index:

  1. GET opensearch_dashboards_sample_data_ecommerce/_search
  2. {
  3. "size": 0,
  4. "query": {
  5. "range": {
  6. "taxful_total_price": {
  7. "lte": 50
  8. }
  9. }
  10. },
  11. "aggs": {
  12. "total_avg_amount": {
  13. "global": {},
  14. "aggs": {
  15. "avg_price": {
  16. "avg": {
  17. "field": "taxful_total_price"
  18. }
  19. }
  20. }
  21. }
  22. }
  23. }

copy

Example response

  1. ...
  2. "aggregations" : {
  3. "total_avg_amount" : {
  4. "doc_count" : 4675,
  5. "avg_price" : {
  6. "value" : 75.05542864304813
  7. }
  8. }
  9. }
  10. }

You can see that the average value for the taxful_total_price field is 75.05 and not the 38.36 as seen in the filter example when the query matched.