Set the retention period for logging and metrics indices

Elastic Cloud Enterprise sets up index lifecycle management (ILM) policies for the ECE platform monitoring data it collects inside the logging-and-metrics system deployment.

By default, metrics indices are retained for two days and logging indices for eight days, as defined in the ece_metrics and ece_logs ILM policies of the deployment. This accounts for daily rollover plus the additional retention periods of one day for metrics and seven days for logs. These default policies and their associated index templates are managed by Elastic Cloud Enterprise and should not be modified.

You might need to adjust the retention period for one of the following reasons:

  • If your business requires you to retain logs and metrics for longer than the default period.
  • If the volume of logs and metrics collected is high enough to require reducing the amount of storage space consumed.
Important

Before increasing retention, ensure the logging-and-metrics system deployment has sufficient resources and disk capacity. Longer retention increases storage usage and cluster workload, and can result in a busy or overloaded cluster if the deployment is not scaled appropriately. Refer to ECE system deployments configuration for more information.

To customize the retention period, create a new ILM policy with the required settings and apply it to the target data streams. On ECE 4.1.1 or later, apply it through a component template, which is the recommended approach. On earlier versions, you can clone the relevant index template and configure it to use your custom ILM policy, though this requires repeating the procedure after upgrades that change template names.

The following list contains the names of the most relevant index templates and data streams in the ECE logging-and-metrics system deployment. You can check the entire list directly in Kibana on the Index Management -> Index templates page:

Index template and data stream name Default ILM policy Description
cluster-logs-<version> ece_logs Logs from all deployments managed by ECE
proxy-logs-<version> ece_logs ECE proxy logs
service-logs-<version> ece_logs Logs produced by internal ECE services
metricbeat-<version> ece_metrics Metrics from all containers and hosts
allocator-metricbeat-<version> ece_metrics Metrics from the Elastic Stack containers running in the allocators
Note

Index templates and data streams include a <version> tag as part of their name. This corresponds to the Elastic Stack version of the internal component that sends data into the cluster, for example, proxy-logs-8.18.8. This version can change after an Elastic Cloud Enterprise upgrade and must be taken into account when you apply any type of customization.

Starting from ECE 4.1.1, each index template in the logging-and-metrics cluster includes a composed_of array that references a set of reserved component template names. If you create a component template with one of these names, Elasticsearch merges its settings into new backing indices automatically. Because these names do not include a version tag, the customization persists across ECE upgrades without any additional action.

The following component template names are reserved for customization. Define only the one that matches the scope you need:

Component template Applies to
cluster-logs@custom cluster-logs-<version> data streams
proxy-logs@custom proxy-logs-<version> data streams
service-logs@custom service-logs-<version> data streams
metricbeat@custom metricbeat-<version> data streams
allocator-metricbeat@custom allocator-metricbeat-<version> data streams
ece-logs@custom All logging data streams
ece-metrics@custom All metrics data streams
ece-all@custom All logging and metrics data streams

If you define multiple @custom component templates, the most specific one takes precedence: an index-specific template (for example, cluster-logs@custom) overrides ece-logs@custom, which in turn overrides ece-all@custom.

To customize the retention period:

  1. Create a new ILM policy with the required retention settings.

  2. Create a component template using the name that matches your target scope, and set index.lifecycle.name to the ILM policy you created. You can do this from Kibana Index Management → Component templates, or from the Kibana Console. For example, to apply a custom ILM policy to all cluster-logs data streams:

    				PUT _component_template/cluster-logs@custom
    					{
      "template": {
        "settings": {
          "index.lifecycle.name": "<MY_CUSTOM_ILM_POLICY>"
        }
      }
    }
    		
  3. If you want the changes to take effect immediately, you can manually roll over the associated data stream using the Kibana Console. For example:

    				POST /cluster-logs-<version>/_rollover/
    		
Note

This method works on all ECE versions but requires repeating the procedure after upgrades that change index template names. If you are on ECE 4.1.1 or later, use the component template method instead.

To customize the retention period for the different data streams, create a new ILM policy with the required settings, and apply it to the relevant data sets as follows:

  1. In Kibana, go to Index Management → Index Templates and identify the template that applies to the data stream or indices whose retention you want to change. Refer to Available index templates for a list of the most common templates.

  2. Open the template's contextual menu and select Clone to create a new template. When cloning the template:

    1. Assign a higher priority to the new template so it takes precedence over the default template.
    2. In the Index settings section, set index.lifecycle.name to the custom ILM policy that has the required retention settings.
    Note

    Cloning an existing index template is recommended over creating one from scratch, so as to ensure that all required mappings and settings are preserved.

  3. Save the new template and verify that it differs from the default template only in the priority and index.lifecycle.name settings.

  4. If you want the changes to take effect immediately, you can manually roll over the associated data stream using the Kibana Console. For example:

    				POST /cluster-logs-<version>/_rollover/
    		

    After the rollover completes, a new backing index is created using the new index template and is associated with the custom ILM policy. You can verify this by checking the data stream information:

    				GET _data_stream/cluster-logs-8.18.8
    		
Important

In Elastic Cloud Enterprise, the names of default index templates and data streams include the Elastic Stack version of the internal component that sends the data (for example, cluster-logs-8.18.8). After an Elastic Cloud Enterprise upgrade, new templates and data stream names can be created with updated version numbers. When this happens, your cloned template might no longer apply, and you must repeat this procedure to ensure your custom ILM policy continues to be applied.