Create a data stream with a lifecycle
Create a classic Elasticsearch data stream with a configured lifecycle. Learn how to set the retention period for your data and to retrieve the lifecycle configuration details.
For wired data streams, go to Get data into Streams and Configure data lifecycle with Streams.
To follow these steps, you need:
Cluster privilege
manage_index_templates, to create the index template.-
create_index,create_doc, andview_index_metadatato create the stream, index documents, and read the lifecycle.auto_configureif you use the bulk indexing API example, which adds mappings for fields that aren't defined in the template.-
manageif you create the stream in Streams, which writes data stream settings.
The All Kibana privilege for the Streams feature. A default snapshot repository and an appropriate license for searchable snapshots if you turn on frozen phase transitions. Refer to Manage snapshot repositories.
A data stream requires a matching index template. Set the lifecycle on that template, in the same place you set mappings and index settings, so every new stream that matches the pattern inherits the lifecycle details.
Find Index Management in the navigation menu or use the global search field.
On the Index Templates tab, click Create template.
On the Logistics page, enter a name and an index pattern that matches the data stream. For example, use
my-index-templatefor the name andmy-data-stream-test*for the index pattern.To use the Streams app in subsequent steps, your index pattern must contain a wildcard ( *).Turn on Create data stream.
Select Delete phase (Data retention in earlier versions), and choose how long to retain your data, in days, hours, minutes, or seconds.
Optional: Select the Frozen phase to choose when to move your data to searchable snapshots, in days, hours, minutes, or seconds. This period must be shorter than the delete phase. Refer to Searchable snapshots for data streams. In Priority, enter a value higher than
500so it doesn't collide with built-in templates. Refer to Avoid index pattern collisions.Complete the rest of the wizard. On the Review page, click Create template. For the other wizard pages, refer to Index templates and Index fundamentals.
Use the create index template API. For example:
PUT _index_template/my-index-template
{
"index_patterns": ["my-data-stream-test*"],
"data_stream": { },
"priority": 501,
"template": {
"lifecycle": {
"data_retention": "7d"
}
},
"_meta": {
"description": "Template with data stream lifecycle"
}
}
- You can use a wildcard (
*) in the index pattern to match every data stream whose name matches the pattern. - Include the
data_streamobject to enable data streams. - Set the priority higher than
500so it doesn't collide with built-in templates. Refer to Avoid index pattern collisions. - Define the lifecycle in the template section or in a component template.
- Choose how long to retain your data, in days, hours, minutes, or seconds.
To move older backing indices to searchable snapshots, include frozen_after in the lifecycle on the template. For requirements and how conversion works, refer to Searchable snapshots for data streams. For example:
PUT _index_template/my-index-template
{
"index_patterns": ["my-data-stream-test*"],
"data_stream": { },
"priority": 501,
"template": {
"lifecycle": {
"data_retention": "365d",
"frozen_after": "30d"
}
},
"_meta": {
"description": "Template with data stream lifecycle and frozen transitions"
}
}
- This period must be shorter than the
data_retentionperiod if both are specified.
Create the data stream after the template exists. The stream name has to match the template's index pattern. Otherwise, the lifecycle on the template doesn't apply.
Create a data stream and load data by submitting API requests in Dev Tools. Refer to the API tab for examples.
Create a classic data stream in Streams: - Find Streams in the navigation menu or use the global search field.
- Click Create classic stream.
- Select the index template, enter the stream name, and click Create.
Create the stream in either of these ways:
With the create data stream API. For example:
PUT _data_stream/my-data-stream-testThe stream's name must match one of your template's index patterns.
With an indexing request. For example:
PUT my-data-stream-test/_bulk{ "create":{ } } { "@timestamp": "2099-05-06T16:21:15.000Z", "message": "192.0.2.42 - - [06/May/2099:16:21:15 +0000] \"GET /images/bg.jpg HTTP/1.0\" 200 24736" } { "create":{ } } { "@timestamp": "2099-05-06T16:25:42.000Z", "message": "192.0.2.255 - - [06/May/2099:16:25:42 +0000] \"GET /favicon.ico HTTP/1.0\" 200 3638" }
Confirm that the data stream uses the lifecycle from the template.
View the data stream in Index Management:
- Find Index Management in the navigation menu or use the global search field.
- Select the Data Streams tab.
- Search for the data stream, and then select it.
- In the flyout, review the data phases (Data retention in earlier versions).
View the data stream in Streams: - Find Streams in the navigation menu or use the global search field.
- Select your stream from the list.
- Select the Data lifecycle tab (Retention in earlier versions).
- Review the lifecycle summary and data phases. For more information, refer to Configure data lifecycle with Streams.
Use the get data stream lifecycle API to view the lifecycle configuration details. For example:
GET _data_stream/my-data-stream-test*/_lifecycle
Result:
{
"data_streams": [
{
"name": "my-data-stream-test",
"lifecycle": {
"enabled": true,
"data_retention": "7d",
"effective_retention": "7d",
"retention_determined_by": "data_stream_configuration"
}
}
],
"global_retention": {}
}
- The name of your data stream.
- Whether the data stream lifecycle is turned on for this data stream.
- The retention period configured for data in this data stream.
- The retention period that the data stream lifecycle uses. Elasticsearch keeps this data for at least 7 days and can delete it later.
Use the explain data stream lifecycle API to view lifecycle details for the backing indices. For example:
GET my-data-stream-test*/_lifecycle/explain
Result:
{
"indices": {
".ds-my-data-stream-test-2026.10.23-000001": {
"index": ".ds-my-data-stream-test-2026.10.23-000001",
"managed_by_lifecycle": true,
"index_creation_date_millis": 1792718438578,
"time_since_index_creation": "22.79m",
"lifecycle": {
"enabled": true,
"data_retention": "7d",
"effective_retention": "7d",
"retention_determined_by": "data_stream_configuration"
}
}
}
}
- The name of the backing index.
- Whether the data stream lifecycle manages this index.
- Time since the index was created.
- The lifecycle configuration applied to this backing index.
- To change or remove the lifecycle on a stream that already exists, refer to Update the lifecycle of a data stream.
- To learn how effective retention is calculated, refer to Setting retention for Elasticsearch data streams.