---
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/4493/api/doc/elasticsearch/operation/operation-indices-downsample
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/operation/operation-indices-downsample
products:
  - Elasticsearch
---

# Downsample an index

Availability: Generally available since 8.7

## Paths

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

#### Path parameters

- `index` (string) — required
  Name of the time series index to downsample.
- `target_index` (string) — required
  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`).

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/token-based-authentication-services)

## Request body

`application/json`

- `fixed_interval` (string) — required
  The interval at which to aggregate the original time series index.
- `sampling_method` (enum) — 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"
  }
)
```

