# $avg

`$avg` computes the arithmetic mean of a field across matching documents.

If `missing` is provided, documents without the field are treated as if they had the `missing` 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. |

<Tabs>

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

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

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

</Tabs>

### Output

```json
{ "avg_price": { "value": 40 } }
```

`value` is `null` when no values are available after filtering.
