# TS.DOWNSAMPLE

> Add a rule that feeds every new sample of one time series into another.

URL: https://docs.hotkv.com/commands/ts-downsample/

```
TS.DOWNSAMPLE source destination aggregation bucket
```

- Group: Time series
- Complexity: O(1)
- HotKV Cloud: Performance and Scale plans
- On-Premise: requires the time-series license feature

`TS.DOWNSAMPLE` adds a rule to the time series `source`: from now on, every
sample added to `source` with [TS.ADD](https://docs.hotkv.com/commands/ts-add/index.md) is also added, as
is, to the time series `destination`. Both series must already exist.
Samples that were in `source` before the rule are not copied.

The rule is recorded with the `aggregation` and `bucket` you give. The
destination holds the raw samples, not aggregated values. To read the
downsampled view, run [TS.AGG](https://docs.hotkv.com/commands/ts-agg/index.md) on the destination with
the same aggregation and bucket. A typical use is to
give the destination a longer retention than the source, or to collect
several sources in one series. The destination's own retention is applied
when a sample is added to it directly, or by
[TS.RETENTION](https://docs.hotkv.com/commands/ts-retention/index.md).

`aggregation` is one of the names [TS.AGG](https://docs.hotkv.com/commands/ts-agg/index.md) accepts, and
`bucket` a width in milliseconds of at least 1. In cluster mode, both series
must hash to the same slot.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Rule added | Simple string `OK` | Simple string `OK` |

Error replies:

- `ERR source or destination series not found`
- `ERR unknown aggregation type` and `ERR invalid bucket size`
- `NOLICENSE ...` without the `time-series` license feature.

## Examples

```
127.0.0.1:6379> TS.CREATE cpu RETENTION 3600000
OK
127.0.0.1:6379> TS.CREATE cpu:history
OK
127.0.0.1:6379> TS.DOWNSAMPLE cpu cpu:history avg 60000
OK
127.0.0.1:6379> TS.ADD cpu * 10
(integer) 1759400000000
127.0.0.1:6379> TS.ADD cpu * 20
(integer) 1759400030000
127.0.0.1:6379> TS.AGG cpu:history - + 60000 avg
1) 1) (integer) 1759399980000
   2) "15.000000"
```

The timestamps come from the server clock and will differ.

## Compatibility

HotKV-only command. It is not the same as RedisTimeSeries `TS.CREATERULE`:
the destination receives raw samples, and you aggregate when you read.

## See also

[TS.AGG](https://docs.hotkv.com/commands/ts-agg/index.md), [TS.CREATE](https://docs.hotkv.com/commands/ts-create/index.md), [TS.INFO](https://docs.hotkv.com/commands/ts-info/index.md)