---
type: api
title: Downsample an index
description: Downsamples a time series (TSDS) index and reduces its size by keeping the last value or by pre-aggregating metrics:
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-indices-downsample
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/operation/operation-indices-downsample
products:
  - Elasticsearch
---

# Downsample an index

Availability: 8.7+

## Paths

- `POST` `/{index}/_downsample/{target_index}`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v9/authentication#bearerauth)

#### Path Parameters

- `index` (string IndexName)
  Name of the time series index to downsample.
- `target_index` (string IndexName)
  Name of the index to create.

## Description

Downsamples a time series (TSDS) index and reduces its size by keeping the last value or by pre-aggregating metrics:

- When running in `aggregate` mode, it pre-calculates and stores statistical summaries (`min`, `max`, `sum`, `value_count` and `avg`)
for each metric field grouped by a configured time interval and their dimensions.
- When running in `last_value` mode, it keeps the last value for each metric in the configured interval and their dimensions.

For example, a TSDS index that contains metrics sampled every 10 seconds can be downsampled to an hourly index.
All documents within an hour interval are summarized and stored as a single document in the downsample index.

NOTE: Only indices in a time series data stream are supported.
Neither field nor document level security can be defined on the source index.
The source index must be read-only (`index.blocks.write: true`).

## Request Body

`application/json`

- `fixed_interval` (string) — required
  The interval at which to aggregate the original time series index.
- `sampling_method` (enum SamplingMethod) — optional
  The sampling method used to reduce the documents; it can be either `aggregate` or `last_value`. Defaults to `aggregate`.
  Values: `aggregate`, `last_value`

## Response

`application/json`

Type: `object`

## Code Examples

#### Console

```console
POST /my-time-series-index/_downsample/my-downsampled-time-series-index
{
  "fixed_interval": "1d"
}
```

#### JavaScript

```javascript
const response = await client.indices.downsample({
  index: "my-time-series-index",
  target_index: "my-downsampled-time-series-index",
  config: {
    fixed_interval: "1d",
  },
});
```

#### Python

```python
resp = client.indices.downsample(
    index="my-time-series-index",
    target_index="my-downsampled-time-series-index",
    config={
        "fixed_interval": "1d"
    },
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/my-time-series-index/_downsample/my-downsampled-time-series-index" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "fixed_interval": "1d"
  }'
```

#### Java

```java
client.indices().downsample(d -> d
    .index("my-time-series-index")
    .targetIndex("my-downsampled-time-series-index")
    .config(c -> c
        .fixedInterval(f -> f
            .time("1d")
        )
    )
);
```

#### C#

```c#
var response = await client.Indices
    .DownsampleAsync(index: "my-time-series-index", targetIndex: "my-downsampled-time-series-index", d1 => d1
        .Config(d2 => d2
            .FixedInterval("1d")
        )
    );
```

#### PHP

```php
$resp = $client->indices()->downsample([
    "index" => "my-time-series-index",
    "target_index" => "my-downsampled-time-series-index",
    "body" => [
        "fixed_interval" => "1d",
    ],
]);
```

#### Ruby

```ruby
response = client.indices.downsample(
  index: "my-time-series-index",
  target_index: "my-downsampled-time-series-index",
  body: {
    "fixed_interval": "1d"
  }
)
```

