Skip to main content
Use SEARCH.AGGREGATE to compute metrics and buckets over matching documents. The command takes two JSON arguments. The first is a filter, in the same language as SEARCH.QUERY, which selects the documents to aggregate; pass '{}' to cover the whole index. The second describes the aggregations to compute, as named entries such as {"avg_price": {"$avg": {"field": "price"}}}. Metric operators like $avg, $sum, $min, $max, $stats, and $cardinality reduce the selected documents to a single number, while bucket operators like $terms, $range, $histogram, and $dateHistogram group them and report a count per bucket. Bucket operators accept nested $aggs, so you can compute a metric inside each bucket, for example the average price per category, and several aggregations can be requested in one call since they all run over the same selected document set. See Aggregations for the full operator reference and examples.

Syntax

<json_filter> is an Upstash JSON filter. The command accepts an index name or alias. See Aggregations for the aggregation object and supported operators.

Response

In redis-cli --json, the response is an object keyed by aggregation alias:
Raw RESP output may be rendered differently by client or protocol settings, but each top-level alias maps to its aggregation result. Returns null if the index does not exist.

Examples