Skip to main content

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.

$cardinality returns the number of distinct values in a field. All matching field values are deduplicated, then counted. If missing is provided, documents without the field are treated as that fallback key (which can increase the distinct count by at most one extra value).

Compatibility

Field TypeSupported
TEXTNo
U64/I64/F64Yes
DATEYes
BOOLYes
KEYWORDYes
FACETNo
Field must be FAST.

Arguments

ArgumentTypeRequiredDescription
fieldstringYesField to aggregate.
missingstring | numberNoFallback key for missing fields.
await index.aggregate({
  aggregations: {
    unique_users: { $cardinality: { field: "userId" } },
  },
});

Output

{ "unique_categories": { "value": 3 } }