﻿---
title: Data stream lifecycle in Elasticsearch
description: A data stream lifecycle in Elasticsearch is a built-in automation mechanism for managing data retention, performance, and storage optimization. By configuring...
url: https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9289/manage-data/lifecycle/data-stream
products:
  - Elastic Documentation
  - Elasticsearch
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Generally available
---

# Data stream lifecycle in Elasticsearch
A data stream lifecycle in Elasticsearch is a built-in automation mechanism for managing data retention, performance, and storage optimization.
By configuring rollover, retention, downsampling, and frozen transitions to long-term searchable archives, your [data streams](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9289/manage-data/data-store/data-streams) stay efficient as they age.
This page explains how the lifecycle works, its key features, and how to configure it for both new and existing data streams.
Data stream lifecycle manages your data streams according to your retention and storage goals. For example, you can configure the lifecycle to:
- Ensure that data indexed in the data stream is kept at least for the retention time you defined.
- Ensure that data older than the retention period is deleted automatically by Elasticsearch at a later time.
- <applies-to>Elastic Stack: Generally available since 9.5</applies-to> <applies-to>Elastic Cloud Serverless: Unavailable</applies-to> Move older backing indices to low-cost searchable storage. Refer to [Searchable snapshots for data streams](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9289/manage-data/lifecycle/data-stream/dlm-searchable-snapshots).

To achieve these, data stream lifecycle supports:
- Automatic [rollover](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9289/manage-data/lifecycle/index-lifecycle-management/rollover), which chunks your incoming data in smaller pieces to facilitate better performance and backwards incompatible mapping changes.
- Configurable retention, which allows you to configure the time period for which your data is guaranteed to be stored. Elasticsearch is allowed at a later time to delete data older than this time period. Retention can be configured on the data stream level or on a global level. Read more about the different options in this [tutorial](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9289/manage-data/lifecycle/data-stream/tutorial-data-stream-retention).

Data stream lifecycle also supports downsampling the data stream backing indices. Refer to [the downsampling example](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-data-lifecycle) for more details.

## Data stream lifecycle availability

Note the availability of data stream lifecycle to ensure that it's applicable for your use case:
- Data stream lifecycle is supported only for data streams and cannot be used with individual indices.
- Data stream lifecycle is supported for all deployment types on the versioned Elastic Stack as well as for Elasticsearch Serverless.


## How does it work?

In intervals configured by [`data_streams.lifecycle.poll_interval`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/configuration-reference/data-stream-lifecycle-settings#data-streams-lifecycle-poll-interval), Elasticsearch goes over each data stream and performs the following steps:
1. Checks if the data stream has a data stream lifecycle configured, skipping any indices not part of a managed data stream. <applies-to>Elastic Stack: Planned</applies-to> A time series data stream without a lifecycle is managed by the [minimum data stream lifecycle](#minimum-data-stream-lifecycle), which runs only steps 2 (roll over) and 3 (tail merge).
2. Rolls over the write index of the data stream, if it fulfills the conditions defined by [`cluster.lifecycle.default.rollover`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/configuration-reference/data-stream-lifecycle-settings#cluster-lifecycle-default-rollover).
3. After an index is not the write index anymore (that is, the data stream has been rolled over), automatically tail merges the index. Data stream lifecycle runs a merge operation that only targets the long tail of small segments instead of the whole shard. As the segments are organised into tiers of exponential sizes, merging the long tail of small segments is only a fraction of the cost of force merging to a single segment. The small segments would usually hold the most recent data so tail merging will focus the merging resources on the higher-value data that is most likely to keep being queried.
4. If [downsampling](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-data-lifecycle) is configured it will run all the configured downsampling rounds. <applies-to>Elastic Stack: Generally available since 9.5</applies-to> <applies-to>Elastic Cloud Serverless: Generally available</applies-to> Data stream lifecycle limits concurrent downsampling per data stream using the [`data_streams.lifecycle.downsampling.max_indices_in_progress`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/configuration-reference/data-stream-lifecycle-settings#data-streams-lifecycle-downsampling-max-indices-in-progress) cluster setting (default `10`). For details, refer to [Downsample with a data stream lifecycle](/elastic/docs-content/pull/9289/manage-data/data-store/data-streams/run-downsampling#downsample-with-a-data-stream-lifecycle).
5. <applies-to>Elastic Stack: Generally available since 9.5</applies-to> <applies-to>Elastic Cloud Serverless: Unavailable</applies-to> Transitions eligible backing indices to partially mounted searchable snapshots. Refer to [Searchable snapshots for data streams](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9289/manage-data/lifecycle/data-stream/dlm-searchable-snapshots).
6. Applies retention to the remaining backing indices. This means deleting the backing indices whose `generation_time` is longer than the effective retention period (read more about the [effective retention calculation](/elastic/docs-content/pull/9289/manage-data/lifecycle/data-stream/tutorial-data-stream-retention#effective-retention-calculation)). The `generation_time` is only applicable to rolled over backing indices and it is either the time since the backing index got rolled over, or the time optionally configured in the [`index.lifecycle.origination_date`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/configuration-reference/data-stream-lifecycle-settings#index-data-stream-lifecycle-origination-date) setting. Retention can delete indices even after they have been moved to searchable snapshots.

<important>
  We use the `generation_time` instead of the creation time because this ensures that all data in the backing index have passed the retention period. As a result, the retention period is not the exact time data gets deleted, but the minimum time data will be stored.
</important>

<note>
  Steps `2-5` apply only to backing indices that are not already managed by ILM, meaning that these indices either do not have an ILM policy defined, or if they do, they have [`index.lifecycle.prefer_ilm`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/configuration-reference/data-stream-lifecycle-settings#index-lifecycle-prefer-ilm) set to `false`.
</note>


## Configuring data stream lifecycle

Since the lifecycle is configured on the data stream level, the process to configure a lifecycle on a new data stream and on an existing one differ.
The following tutorials help you set up and manage data streams with data stream lifecycle:
- To create a new data stream with a lifecycle, add the data stream lifecycle as part of the index template that matches the name of your data stream. Refer to [Create a data stream with a lifecycle](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9289/manage-data/lifecycle/data-stream/tutorial-create-data-stream-with-lifecycle) for the detailed steps. When a write operation with the name of your data stream reaches Elasticsearch then the data stream is created with the respective data stream lifecycle.
- To update the lifecycle settings for an individual, existing data stream, use the [data stream lifecycle APIs](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-data-stream). Refer to [Update the lifecycle of a data stream](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9289/manage-data/lifecycle/data-stream/tutorial-update-existing-data-stream) for details.
- Retention settings for data streams can be configured both individually, at the data stream level, and globally, for all data streams in a cluster. To learn more, refer to [Setting retention for Elasticsearch data streams](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9289/manage-data/lifecycle/data-stream/tutorial-data-stream-retention).
- To migrate an existing ILM managed data stream to data stream lifecycle, follow the steps in [Migrating ILM-managed data streams to data stream lifecycle](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9289/manage-data/lifecycle/data-stream/tutorial-migrate-ilm-managed-data-stream-to-data-stream-lifecycle).
- <applies-to>Elastic Stack: Generally available since 9.5</applies-to> <applies-to>Elastic Cloud Serverless: Unavailable</applies-to> To move older backing indices to searchable snapshots, refer to [Searchable snapshots for data streams](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9289/manage-data/lifecycle/data-stream/dlm-searchable-snapshots).

<note>
  Updating the data stream lifecycle of an existing data stream is different from updating the settings or the mapping, because it is applied on the data stream level and not on the individual backing indices.
</note>


## Minimum data stream lifecycle

<applies-to>
  - Elastic Cloud Serverless: Unavailable
  - Elastic Stack: Planned
</applies-to>

Elasticsearch manages time series data stream (TSDS) that have no data stream lifecycle of their own with a minimum lifecycle. The minimum lifecycle performs only the operations a data stream needs to stay healthy: [rollover](https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/9289/manage-data/lifecycle/index-lifecycle-management/rollover) and tail merging. It never changes the data set, so it doesn't downsample, move data to searchable snapshots, or delete data. It doesn't delete data even if you configure a global retention.
The minimum lifecycle applies to a data stream when all the following are true:
- The data stream is a TSDS.
- The data stream does not have data stream lifecycle configured. A data stream with a lifecycle that is explicitly turned off keeps that configuration and the minimum lifecycle does not apply.
- The [`data_streams.lifecycle.minimum.enabled`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/configuration-reference/data-stream-lifecycle-settings#data-streams-lifecycle-minimum-enabled) cluster setting is `true`, which is the default.
- The backing indices are not managed by ILM policies. A backing index with an ILM policy stays managed by ILM unless [`index.lifecycle.prefer_ilm`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/configuration-reference/data-stream-lifecycle-settings#index-lifecycle-prefer-ilm) is `false`.

Adding a data stream lifecycle to the data stream replaces the minimum lifecycle with your configuration.
<important>
  Before 9.6, a TSDS without a lifecycle or an ILM policy was never rolled over automatically. If an external process rolls over your TSDS, you might now see additional backing indices. A TSDS that has an ILM policy, `index.lifecycle.prefer_ilm` set to `false`, and no data stream lifecycle also moves from ILM to the minimum lifecycle. As a result, ILM phases such as delete or downsample stop running for it.To restore the previous behavior, set `data_streams.lifecycle.minimum.enabled` to `false`. The setting is dynamic, so you don't need to restart Elasticsearch.
  ```console
  PUT _cluster/settings
  {
    "persistent": {
      "data_streams.lifecycle.minimum.enabled": false
    }
  }
  ```
</important>


### Pre-installed lifecycle management for `metrics` moves to the minimum lifecycle

<applies-to>
  - Elastic Cloud Serverless: Unavailable
  - Elastic Stack: Planned
</applies-to>

<applies-to>Elastic Stack: Planned</applies-to> Elasticsearch migrates time series data stream that use the pre-installed `metrics` ILM policy from ILM to the minimum lifecycle.

#### How it works

For new backing indices of a TSDS that uses the **pre-installed and unmodified** `metrics` policy, Elasticsearch defaults [`index.lifecycle.prefer_ilm`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/configuration-reference/data-stream-lifecycle-settings#index-lifecycle-prefer-ilm) to `false`. The policy stays attached to the index, but ILM no longer manages it. If the data stream has its own data stream lifecycle, that lifecycle manages the index. Otherwise, the minimum lifecycle does.

#### When it applies

The new default for [`index.lifecycle.prefer_ilm`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/configuration-reference/data-stream-lifecycle-settings#index-lifecycle-prefer-ilm) applies to a backing index only when all the following are true:
- The index is created in <applies-to>Elastic Stack: Planned</applies-to>. Existing backing indices stay under ILM until they are deleted or you change them manually.
- The data stream is a TSDS that uses the `metrics` policy, and the policy is unmodified. Data streams that use a custom policy or a modified `metrics` policy remain unaffected.
- No `index.lifecycle.prefer_ilm` value is set in the index template, the data stream settings, or the create index request. An explicit value always takes precedence.
- The [`data_streams.lifecycle.prefer_by_default.metrics_enabled`](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/elasticsearch/configuration-reference/data-stream-lifecycle-settings#data-streams-lifecycle-prefer-by-default-metrics-enabled) cluster setting is `true`, which is the default.


#### Revert to ILM

Choose the option that matches the scope you need:
- **All new backing indices in the cluster:** Set the dynamic cluster setting `data_streams.lifecycle.prefer_by_default.metrics_enabled` to `false`. This doesn't change backing indices that already have `prefer_ilm` set to `false`.
- **New backing indices of specific data streams:** Set `index.lifecycle.prefer_ilm` to `true` in the component or index template.
- **Existing backing indices of a data stream:** Update the data stream settings. The following request changes `prefer_ilm` on all backing indices of the data stream:
  ```console
  PUT _data_stream/my-time-series/_settings
  {
    "index.lifecycle.prefer_ilm": true
  }
  ```


### Check what manages a data stream

To check whether the minimum lifecycle manages a data stream or an index, use the following APIs:
- [Get data stream API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-data-stream): returns `"minimum_lifecycle_enabled": true` and `"next_generation_managed_by": "Data stream lifecycle"` for the data stream.
- [Get data stream lifecycle API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-data-lifecycle): returns `"minimum_lifecycle_enabled": true` for the data stream.
- [Explain data stream lifecycle API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-explain-data-lifecycle): returns `"minimum_lifecycle_enabled": true` for each index the minimum lifecycle manages. For indices that no lifecycle manages, the response includes an `unmanaged_reason` field when Elasticsearch can determine why. The [ILM explain API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-ilm-explain-lifecycle) includes the same field.