Metric Aggregations
$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
missingis 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. |
await index.aggregate({ aggregations: { price_count: { $count: { field: "price" } }, },});index.aggregate( aggregations={"price_count": {"$count": {"field": "price"}}})SEARCH.AGGREGATE products '{}' '{"price_count": {"$count": {"field": "price"}}}'Output
{ "price_count": { "value": 9 } }