Sum aggregation

Sum aggregation #

A single-value metrics aggregation that sums up numeric values that are extracted from the aggregated documents.

Examples #

Assuming the data consists of documents representing sales records we can sum the sale price of all hats with:

POST /sales/_search
{
  "query": {
    "constant_score": {
      "filter": {
        "match": {
          "type": "hat"
        }
      }
    }
  },
  "aggs": {
    "hat_prices": {
      "sum": {
        "field": "price"
      }
    }
  }
}

Resulting in:

{
  ...
  "aggregations": {
    "hat_prices": {
      "value": 450.0
    }
  }
}

The name of the aggregation (hat_prices above) also serves as the key by which the aggregation result can be retrieved from the returned response.

Parameters for avg #

  • field
    (Required, string) Field you wish to aggregate.
Calendar August 28, 2024
Edit Edit this page