# $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 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. |

<Tabs>

<Tab title="TypeScript">
```ts
await index.aggregate({
  aggregations: {
    price_extended: {
      $extendedStats: { field: "price", sigma: 2, missing: 0 },
    },
  },
});
```
</Tab>

<Tab title="Python">
```python
index.aggregate(
    aggregations={
        "price_extended": {
            "$extendedStats": {"field": "price", "sigma": 2, "missing": 0}
        }
    }
)
```
</Tab>

<Tab title="Redis CLI">
```bash
SEARCH.AGGREGATE products '{}' '{"price_extended": {"$extendedStats": {"field": "price", "sigma": 2, "missing": 0}}}'
```
</Tab>

</Tabs>

### Output

Returns a single object containing all basic and extended fields. Example shape:

```json
{ "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 }
  }
}
```
