> ## Documentation Index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# $count

`$count` returns how many documents contribute a value for a field.

### How It Works

* By default, only documents that have the field are counted.
* If `missing` is set, documents without the field also contribute to result.

### Compatibility

| Field Type | Supported |
| - | - |
| TEXT | No |
| U64/I64/F64 | Yes |
| DATE | Yes |
| BOOL | Yes |
| KEYWORD | Yes |
| FACET | No |

Field must be `FAST`.

### Arguments

| Argument | Type | Required | Description |
| - | - | - | - |
| `field` | `string` | Yes | Field to count values for. |
| `missing` | `number` | No | Fallback value for missing fields. |

> [tab] TypeScript
>
> ```ts theme={"system"}
> await index.aggregate({
>   aggregations: {
>     price_count: { $count: { field: "price" } },
>   },
> });
> ```

> [tab] Python
>
> ```python theme={"system"}
> index.aggregate(
>     aggregations={"price_count": {"$count": {"field": "price"}}}
> )
> ```

> [tab] Redis CLI
>
> ```bash theme={"system"}
> SEARCH.AGGREGATE products '{}' '{"price_count": {"$count": {"field": "price"}}}'
> ```

### Output

```json theme={"system"}
{ "price_count": { "value": 9 } }
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.