Metric Aggregations
$sum
$sum computes the total of a field across matching documents.
If missing is set, missing fields contribute that fallback value.
Compatibility
| Field Type | Supported |
|---|---|
| TEXT | No |
| U64/I64/F64 | Yes |
| DATE | Yes |
| BOOL | Yes |
| KEYWORD | No |
| FACET | No |
Field must be FAST.
Arguments
| Argument | Type | Required | Description |
|---|---|---|---|
field | string | Yes | Field to aggregate. |
missing | number | No | Fallback value for missing fields. |
await index.aggregate({ aggregations: { total_price: { $sum: { field: "price", missing: 0 } }, },});index.aggregate( aggregations={"total_price": {"$sum": {"field": "price", "missing": 0}}})SEARCH.AGGREGATE products '{}' '{"total_price": {"$sum": {"field": "price", "missing": 0}}}'Output
{ "total_price": { "value": 360 } }value can be null when no values are available.