Aggregations let you compute analytics over your indexed data — metrics like averages, sums, and statistics, as well as bucket-based groupings like terms, ranges, and histograms. They are useful when you want to answer questions like:Documentation Index
Fetch the complete documentation index at: https://upstash-cloud-4245.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
- “What is the average price?”
- “How many unique users do we have?”
- “How many orders fall into each price range?”
- “How does traffic change per hour/day?”
- TypeScript
- Python
- Redis CLI
- Document selection: Optional
filterselects which documents participate. - Aggregation computation: the selected set is reduced into metric values and/or buckets.
Response Format
- TypeScript
- Python
- Redis CLI
Each SDK normalizes response keys to match its language’s conventions: camelCase for TypeScript
(e.g.,
docCount) and snake_case for Python (e.g., doc_count). In redis-cli --json, Redis CLI
returns a JSON object keyed by aggregation alias.All metric aggregation operators require the target field to be marked as
FAST in your schema.
If the field is not FAST, you will get an error like:
Aggregation '<name>' operator '$avg' requires field '<field>' to be FAST.
See FAST Fields for details.Filtering
Usefilter to restrict which documents participate in the aggregation.
Filtering uses the same query syntax as queries.
- TypeScript
- Python
- Redis CLI
Multiple Aggregations in One Request
You can compute multiple top-level aggregations in one call by defining multiple aliases underaggregations.
Each alias is computed against the same filtered document set.
- TypeScript
- Python
- Redis CLI
Nested Aggregations
Bucket operators can include sub-aggregations via$aggs, so you can compute per-bucket metrics.
$terms,$range,$histogram, and$dateHistogramsupport nested$aggs.$facetdoes not support nested$aggs.- Metric operators do not support nested
$aggs.
- TypeScript
- Python
- Redis CLI
Operator Families
Metric Aggregations
Metric aggregations return numeric summaries.| Operator | Typical use |
|---|---|
$avg | Mean value |
$sum | Total |
$min | Smallest value |
$max | Largest value |
$count | Number of values |
$cardinality | Number of distinct values |
$stats | Basic summary stats |
$extendedStats | Stats + variance/std deviation |
$percentiles | Distribution cut points |
Bucket Aggregations
Bucket aggregations partition documents into groups.| Operator | Typical use |
|---|---|
$terms | Top values by field |
$range | Custom ranges |
$histogram | Fixed numeric bins |
$dateHistogram | Fixed time bins |
$facet | Hierarchical facets |