Metric Aggregations

$extendedStats

$extendedStats returns $stats plus additional distribution metrics.

In addition to count, sum, min, max, and avg, this operator provides:

  • sumOfSquares
  • variance, variancePopulation, varianceSampling
  • stdDeviation, stdDeviationPopulation, stdDeviationSampling
  • stdDeviationBounds (upper, lower, plus sampling/population variants)

sigma controls the width of stdDeviationBounds.

Compatibility

Field TypeSupported
TEXTNo
U64/I64/F64Yes
DATEYes
BOOLNo
KEYWORDNo
FACETNo

Field must be FAST.

Arguments

ArgumentTypeRequiredDescription
fieldstringYesField to aggregate.
missingnumberNoFallback value for missing fields.
sigmanumberNoMultiplier 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 }  }}
Loading search…