﻿---
title: Create a data stream with a lifecycle
description: Create an Elasticsearch data stream with a lifecycle. Create an index template with data retention, create a data stream, and confirm the lifecycle.
url: https://www.elastic.co/docs/manage-data/lifecycle/data-stream/tutorial-create-data-stream-with-lifecycle
products:
  - Elastic Documentation
  - Elasticsearch
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Generally available
---

# 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](https://www.elastic.co/docs/solutions/observability/streams/get-data-in) and [Configure data lifecycle with Streams](https://www.elastic.co/docs/solutions/observability/streams/configure-retention).

## Before you begin

To follow these steps, you need:
- [Cluster privilege](https://docs-demo.elastic.dev/docs/reference/elasticsearch/security-privileges#privileges-list-cluster) `manage_index_templates`, to create the index template.
- [Index privileges](https://docs-demo.elastic.dev/docs/reference/elasticsearch/security-privileges#privileges-list-indices):
  - `create_index`, `create_doc`, and `view_index_metadata` to create the stream, index documents, and read the lifecycle.
  - `auto_configure` if you use the bulk indexing API example, which adds mappings for fields that aren't defined in the template.
  - <applies-to>Elastic Stack: Generally available since 9.3</applies-to> <applies-to>Serverless Elasticsearch projects: Unavailable</applies-to> <applies-to>Serverless Elasticsearch Vector Database projects: Unavailable</applies-to> `manage` if you create the stream in **Streams**, which writes data stream settings.
  Refer to [Granting privileges for data streams and aliases](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/granting-privileges-for-data-streams-aliases).
- <applies-to>Elastic Stack: Generally available since 9.3</applies-to> <applies-to>Serverless Elasticsearch projects: Unavailable</applies-to> <applies-to>Serverless Elasticsearch Vector Database projects: Unavailable</applies-to> The **All** [Kibana privilege](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/kibana-privileges) for the **Streams** feature.
- <applies-to>Elastic Stack: Generally available since 9.5</applies-to> <applies-to>Elastic Cloud Serverless: Unavailable</applies-to> A default snapshot repository and an [appropriate license](https://www.elastic.co/subscriptions) for searchable snapshots if you turn on frozen phase transitions. Refer to [Manage snapshot repositories](https://www.elastic.co/docs/deploy-manage/tools/snapshot-and-restore/manage-snapshot-repositories).


## Create an index template

A data stream requires a matching [index template](https://www.elastic.co/docs/manage-data/data-store/templates).
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.
<tab-set>
  <tab-item title="Kibana">
    1. Find **Index Management** in the navigation menu or use the [global search field](https://www.elastic.co/docs/explore-analyze/find-and-organize/find-apps-and-objects).
    2. On the **Index Templates** tab, click **Create template**.
    3. On the **Logistics** page, enter a name and an index pattern that matches the data stream. For example, use `my-index-template` for the name and `my-data-stream-test*` for the index pattern.
       <applies-to>Elastic Stack: Generally available since 9.3</applies-to> <applies-to>Serverless Elasticsearch projects: Unavailable</applies-to> <applies-to>Serverless Elasticsearch Vector Database projects: Unavailable</applies-to> To use the **Streams** app in subsequent steps, your index pattern must contain a wildcard (`*`).
    4. Turn on **Create data stream**.
    5. Select **Delete phase** (**Data retention** in earlier versions), and choose how long to retain your data, in days, hours, minutes, or seconds.
    6. <applies-to>Elastic Stack: Generally available since 9.5</applies-to> <applies-to>Elastic Cloud Serverless: Unavailable</applies-to> 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](https://www.elastic.co/docs/manage-data/lifecycle/data-stream/dlm-searchable-snapshots).
    7. In **Priority**, enter a value higher than `500` so it doesn't collide with built-in templates. Refer to [Avoid index pattern collisions](/docs/manage-data/data-store/templates#avoid-index-pattern-collisions).
    8. Complete the rest of the wizard. On the **Review** page, click **Create template**. For the other wizard pages, refer to [Index templates](https://www.elastic.co/docs/manage-data/data-store/templates) and [Index fundamentals](https://www.elastic.co/docs/manage-data/data-store/index-basics).
  </tab-item>

  <tab-item title="API">
    Use the [create index template API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-index-template).
    For example:
    ```json

    {
      "index_patterns": ["my-data-stream-test*"], <1>
      "data_stream": { }, <2>
      "priority": 501, <3>
      "template": { 
        "lifecycle": { <4>
          "data_retention": "7d" <5>
        }
      },
      "_meta": {
        "description": "Template with data stream lifecycle"
      }
    }
    ```

    <tip applies-to="Elastic Cloud Serverless: Unavailable, Elastic Stack: Generally available since 9.5">
      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](https://www.elastic.co/docs/manage-data/lifecycle/data-stream/dlm-searchable-snapshots). For example:
      ```json

      {
        "index_patterns": ["my-data-stream-test*"],
        "data_stream": { },
        "priority": 501,
        "template": {
          "lifecycle": {
            "data_retention": "365d",
            "frozen_after": "30d" <1>
          }
        },
        "_meta": {
          "description": "Template with data stream lifecycle and frozen transitions"
        }
      }
      ```
    </tip>
  </tab-item>
</tab-set>


## Create a data stream

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.
<tab-set>
  <tab-item title="Kibana">
    - Create a data stream and load data by submitting API requests in [Dev Tools](https://www.elastic.co/docs/explore-analyze/query-filter/tools/console). Refer to the API tab for examples.
    - <applies-to>Elastic Stack: Generally available since 9.3</applies-to> <applies-to>Serverless Elasticsearch projects: Unavailable</applies-to> <applies-to>Serverless Elasticsearch Vector Database projects: Unavailable</applies-to> Create a classic data stream in [Streams](https://www.elastic.co/docs/solutions/observability/streams/streams):
      1. Find **Streams** in the navigation menu or use the [global search field](https://www.elastic.co/docs/explore-analyze/find-and-organize/find-apps-and-objects).
      2. Click **Create classic stream**.
      3. Select the index template, enter the stream name, and click **Create**.
  </tab-item>

  <tab-item title="API">
    Create the stream in either of these ways:
    - With the [create data stream API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-create-data-stream). For example:
      ```json
      ```
      The stream's name must match one of your template's index patterns.
    - With an [indexing request](/docs/manage-data/data-store/data-streams/use-data-stream#add-documents-to-a-data-stream). For example:
      ```json

      { "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" }
      ```
  </tab-item>
</tab-set>


## Retrieve lifecycle information

Confirm that the data stream uses the lifecycle from the template.
<tab-set>
  <tab-item title="Kibana">
    - View the data stream in **Index Management**:
      1. Find **Index Management** in the navigation menu or use the global search field.
      2. Select the **Data Streams** tab.
      3. Search for the data stream, and then select it.
      4. In the flyout, review the data phases (**Data retention** in earlier versions).
    - <applies-to>Elastic Stack: Generally available since 9.3</applies-to> <applies-to>Serverless Elasticsearch projects: Unavailable</applies-to> <applies-to>Serverless Elasticsearch Vector Database projects: Unavailable</applies-to> View the data stream in [Streams](https://www.elastic.co/docs/solutions/observability/streams/streams):
      1. Find **Streams** in the navigation menu or use the [global search field](https://www.elastic.co/docs/explore-analyze/find-and-organize/find-apps-and-objects).
      2. Select your stream from the list.
      3. Select the **Data lifecycle** tab (**Retention** in earlier versions).
      4. Review the lifecycle summary and data phases. For more information, refer to [Configure data lifecycle with Streams](https://www.elastic.co/docs/solutions/observability/streams/configure-retention).
  </tab-item>

  <tab-item title="API">
    Use the [get data stream lifecycle API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-data-lifecycle) to view the lifecycle configuration details.
    For example:
    ```json
    ```
    **Result:**
    ```json
    {
      "data_streams": [
        {
          "name": "my-data-stream-test",                                
          "lifecycle": {
            "enabled": true,                                            
            "data_retention": "7d",                                     
            "effective_retention": "7d",                                
            "retention_determined_by": "data_stream_configuration"
          }
        }
      ],
      "global_retention": {}
    }
    ```
    Use the [explain data stream lifecycle API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-explain-data-lifecycle) to view lifecycle details for the backing indices.
    For example:
    ```json
    ```
    **Result:**
    ```json
      {
        "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"
            }
          }
        }
      }
    ```
  </tab-item>
</tab-set>


## Next steps

- To change or remove the lifecycle on a stream that already exists, refer to [Update the lifecycle of a data stream](https://www.elastic.co/docs/manage-data/lifecycle/data-stream/tutorial-update-existing-data-stream).
- To learn how effective retention is calculated, refer to [Setting retention for Elasticsearch data streams](https://www.elastic.co/docs/manage-data/lifecycle/data-stream/tutorial-data-stream-retention).


## Related pages

- [Data streams in Elasticsearch](https://www.elastic.co/docs/manage-data/data-store/data-streams)
- [Data stream lifecycle in Elasticsearch](https://www.elastic.co/docs/manage-data/lifecycle/data-stream)
- [Index templates in Elasticsearch](https://www.elastic.co/docs/manage-data/data-store/templates)
- [Streams](https://www.elastic.co/docs/solutions/observability/streams/streams)