[[dlm-put-lifecycle]]
=== Set the lifecycle of a data stream
++++
<titleabbrev>Put Data Stream Lifecycle</titleabbrev>
++++

experimental::[]

Configures the data lifecycle for the targeted data streams.

[[dlm-put-lifecycle-request]]
==== {api-request-title}

`PUT _data_stream/<data-stream>/_lifecycle`

[[dlm-put-lifecycle-desc]]
==== {api-description-title}

Configures the data lifecycle for the targeted data streams. If multiple data streams are provided but at least one of them
does not exist, then the update of the lifecycle will fail for all of them and the API will respond with `404`.

[[dlm-put-lifecycle-path-params]]
==== {api-path-parms-title}

`<data-stream>`::
(Required, string) Comma-separated list of data streams used to limit the request. Supports wildcards (`*`).
To target all data streams use `*` or `_all`.

[role="child_attributes"]
[[put-data-lifecycle-api-query-parms]]
==== {api-query-parms-title}

include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=ds-expand-wildcards]
+
Defaults to `open`.

[[put-lifecycle-api-request-body]]
==== {api-request-body-title}

`lifecycle`::
(Required, object)
+
.Properties of `lifecycle`
[%collapsible%open]
====
`data_retention`::
(Optional, string)
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.
====

[[dlm-put-lifecycle-example]]
==== {api-examples-title}

The following example sets the lifecycle of `my-data-stream`:

[source,console]
--------------------------------------------------
PUT _data_stream/my-data-stream/_lifecycle
{
  "lifecycle": {
    "data_retention": "7d"
  }
}
--------------------------------------------------
// TEST[setup:my_data_stream]
// TEST[teardown:data_stream_cleanup]

When the lifecycle is successfully updated in all data streams, you receive the following result:

[source,console-result]
--------------------------------------------------
{
  "acknowledged": true
}
--------------------------------------------------
