---
type: api
title: Update data stream lifecycles
description: Update the data stream lifecycle of the specified data streams.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch-serverless/operation/operation-indices-put-data-lifecycle
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch-serverless/operation/operation-indices-put-data-lifecycle
products:
  - Elasticsearch Serverless
---

# Update data stream lifecycles

Availability:

## Paths

- `PUT` `/_data_stream/{name}/_lifecycle`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch-serverless/authentication#apikeyauth)

#### Path Parameters

- `name` (union DataStreamName | [] DataStreamName)
  Comma-separated list of data streams used to limit the request.
Supports wildcards (`*`).
To target all data streams use `*` or `_all`.

## Description

Update the data stream lifecycle of the specified data streams.

[About data stream lifecycle](https://www.elastic.co/docs/manage-data/lifecycle/data-stream)

## Query String Parameters

- `expand_wildcards` (string ExpandWildcards · default: open)
  Type of data stream that wildcard patterns can match.
Supports comma-separated values, such as `open,hidden`.

Supported values include:
  - `all`: Match any data stream or index, including hidden ones.
  - `open`: Match open, non-hidden indices. Also matches any non-hidden data stream.
  - `closed`: Match closed, non-hidden indices. Also matches any non-hidden data stream. Data streams cannot be closed.
  - `hidden`: Match hidden data streams and hidden indices. Must be combined with `open`, `closed`, or `both`.
  - `none`: Wildcard expressions are not accepted.
  Values: `all`, `open`, `closed`, `hidden`, `none`
- `master_timeout` (string Duration · default: 30s)
  Period to wait for a connection to the master node. If no response is
received before the timeout expires, the request fails and returns an
error.
- `timeout` (string Duration · default: 30s)
  Period to wait for a response.
If no response is received before the timeout expires, the request fails and returns an error.

## Request Body

`application/json`

- `data_retention` (string Duration) — optional
  If defined, every document added to this data stream will be stored at least for this time frame.
Any time after this duration the document could be deleted.
When empty, every document in this data stream will be stored indefinitely.
- `downsampling` ([] DownsamplingRound) — optional
  The downsampling configuration to execute for the managed backing index after rollover.
  - `after` (string Duration) — required
    The duration since rollover when this downsampling round should execute
  - `fixed_interval` (string) — required
    The downsample interval.
- `downsampling_method` (enum SamplingMethod) — optional
  The method used to downsample the data. There are two options `aggregate` and `last_value`. It requires
`downsampling` to be defined. Defaults to `aggregate`.
  Values: `aggregate`, `last_value`
- `enabled` (boolean · default: true) — optional
  If defined, it turns data stream lifecycle on/off (`true`/`false`) for this data stream. A data stream lifecycle
that's disabled (enabled: `false`) will have no effect on the data stream.

## Response

`application/json`

- `acknowledged` (boolean)
  For a successful response, this value is always true. On failure, an exception is returned instead.
## Code Examples

#### Console

```console
PUT _data_stream/my-data-stream/_lifecycle
{
  "data_retention": "7d"
}
```

#### JavaScript

```javascript
const response = await client.indices.putDataLifecycle({
  name: "my-data-stream",
  data_retention: "7d",
});
```

#### Python

```python
resp = client.indices.put_data_lifecycle(
    name="my-data-stream",
    data_retention="7d",
)
```

#### curl

```curl
curl -X PUT "$ELASTICSEARCH_URL/_data_stream/my-data-stream/_lifecycle" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "data_retention": "7d"
  }'
```

#### Java

```java
client.indices().putDataLifecycle(p -> p
    .dataRetention(d -> d
        .time("7d")
    )
    .name("my-data-stream")
);
```

#### C#

```c#
var response = await client.Indices
    .PutDataLifecycleAsync(name: new[] { "my-data-stream" }, d1 => d1
        .DataRetention("7d")
    );
```

#### PHP

```php
$resp = $client->indices()->putDataLifecycle([
    "name" => "my-data-stream",
    "body" => [
        "data_retention" => "7d",
    ],
]);
```

#### Ruby

```ruby
response = client.indices.put_data_lifecycle(
  name: "my-data-stream",
  body: {
    "data_retention": "7d"
  }
)
```

## Response Examples

#### Indices put data lifecycle response example1

A successful response for configuring a data stream lifecycle.

```json
{
  "acknowledged": true
}
```

