Metric Aggregations
$extendedStats
$extendedStats returns $stats plus additional distribution metrics.
In addition to count, sum, min, max, and avg, this operator provides:
sumOfSquaresvariance,variancePopulation,varianceSamplingstdDeviation,stdDeviationPopulation,stdDeviationSamplingstdDeviationBounds(upper,lower, plus sampling/population variants)
sigma controls the width of stdDeviationBounds.
Compatibility
| Field Type | Supported |
|---|---|
| TEXT | No |
| U64/I64/F64 | Yes |
| DATE | Yes |
| BOOL | No |
| 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. |
sigma | number | No | Multiplier used for standard deviation bounds. |
await index.aggregate({ aggregations: { price_extended: { $extendedStats: { field: "price", sigma: 2, missing: 0 }, }, },});index.aggregate( aggregations={ "price_extended": { "$extendedStats": {"field": "price", "sigma": 2, "missing": 0} } })SEARCH.AGGREGATE products '{}' '{"price_extended": {"$extendedStats": {"field": "price", "sigma": 2, "missing": 0}}}'Output
Returns a single object containing all basic and extended fields. Example shape:
{ "price_extended": { "count": 9, "min": 0, "max": 80, "avg": 40, "sum": 360, "sumOfSquares": 18000, "variance": 200, "stdDeviation": 14.14, "stdDeviationBounds": { "upper": 68.28, "lower": 11.72 } }}