Index Lifecycle Management (ILM)
7 min read
Managing data inside Elasticsearch is a lot like running a massive shipping warehouse. New boxes (documents) arrive constantly. You need them right at the loading dock so you can unpack and inspect them quickly. But as boxes get older, keeping them at the premium loading dock blocks new shipments. You move them to the back shelves. Eventually, when nobody asks for those boxes anymore, you throw them in the incinerator to make room.
If you forget to move the boxes, your loading dock grinds to a halt. If you keep everything forever, you go bankrupt paying for warehouse space.
This guide will walk you through Index Lifecycle Management (ILM), the automated system that handles moving, shrinking, and deleting your data as it ages so you don't have to do it manually.
1. Time-Series Data: The Need for Index Management
The Problem
In modern systems, applications generate massive volumes of continuous data—like application logs, server metrics, or user clickstreams. If you push all this data into a single Elasticsearch index (e.g., logs), that index will grow infinitely.
A 5-terabyte index with a billion documents is an operational nightmare. It takes forever to back up, consumes massive amounts of memory, and if a node crashes, migrating that massive shard across the network will cripple your cluster. Conversely, creating a new index manually every single day (logs-2026-02-25) leads to thousands of tiny indices, which exhausts cluster metadata and crashes the master nodes (a condition known as "mapping explosion" or "shard exhaustion").
The Definition
Time-series data is continuous data where the primary axis is time. Once written, time-series data is rarely updated.
The Solution: Index Management
Instead of one giant index or thousands of tiny ones, industry standards dictate grouping time-series data into manageable chunks based on size or age. Index Lifecycle Management (ILM) is an Elasticsearch feature that automatically manages indices based on predefined rules like size, document count, or age. It automatically handles creating new indices when old ones get too big, moving old data to cheaper hardware, and deleting data you no longer legally or operationally need to keep.
2. Defining ILM Policies: Hot, Warm, Cold, and Delete Phases
The Problem
High-performance NVMe Solid State Drives (SSDs) are expensive. Storing 5-year-old "User logged in" logs on high-speed SSDs is a massive waste of company money. You need a way to transition data to cheaper, slower disks as it ages.
The Definition
An ILM Policy is a set of JSON rules configured in Elasticsearch that defines how an index should transition through different phases of its life.
Elasticsearch divides the lifecycle into up to five phases. Industry practice typically focuses on three or four:
- Hot Phase: The index is actively being updated (written to) and heavily queried. Data sits on your most expensive, fastest nodes.
- Warm Phase: The index is no longer being written to (read-only), but is still queried frequently. Data is moved to cheaper, slower nodes (like standard SSDs or fast HDDs). You can shrink the index here to save cluster resources.
- Cold Phase: The index is no longer updated and rarely queried. Data sits on the cheapest storage possible.
- Delete Phase: The index is permanently deleted from the cluster.
💡 Under the hood: When an index transitions from Hot to Warm, Elasticsearch updates the index routing allocation settings. The cluster actively copies the physical shards from the "Hot" servers to the "Warm" servers over the network, and then deletes the original hot copies.
Industry Standard Hands-on Example
Here is how you define a practical, frequently used ILM policy via the Elasticsearch Dev Tools API. We want data to stay in "Hot" until it reaches 50GB, then move to "Warm", and finally be deleted after 30 days.
PUT _ilm/policy/company_logs_policy
{
"policy": {
"phases": {
"hot": {
"actions": {
"rollover": {
"max_primary_shard_size": "50gb",
"max_age": "3 days"
}
}
},
"warm": {
"min_age": "7 days",
"actions": {
"forcemerge": {
"max_num_segments": 1
},
"allocate": {
"require": {
"data": "warm"
}
}
}
},
"delete": {
"min_age": "30 days",
"actions": {
"delete": {}
}
}
}
}
}Notice the forcemerge action in the warm phase. Since the index is now read-only, we force Elasticsearch to compress the underlying Lucene segments into a single file. This drastically speeds up searches and saves disk space.
3. Rollover Patterns for Time-Series Indices
The Problem
If we tell Elasticsearch "keep data in the Hot phase until it hits 50GB," how does the application know where to send new data once the index crosses 50GB? If your application is hardcoded to write to logs-000001, and logs-000001 reaches 50GB, the application will fail if Elasticsearch suddenly locks it.
The Definition
Rollover is the process of creating a new index when the current active index reaches a specific size, document count, or age.
How the Concept Solves the Problem: The Alias Pattern
To solve the hardcoding problem, Elasticsearch uses an Index Alias. An alias is a virtual pointer.
Instead of your application writing to logs-000001, it writes to the alias logs_write.
logs_writepoints tologs-000001.- When
logs-000001hits 50GB, the ILM policy triggers a Rollover. - Elasticsearch creates
logs-000002. - Elasticsearch automatically updates the
logs_writealias to point tologs-000002. logs-000001is marked as read-only and begins its journey toward the Warm and Delete phases.
Your application never knows anything changed. It just keeps blindly firing JSON documents at logs_write.
⚠️ Industry Fact: The gold standard for rollover is 50GB per primary shard. Lucene (the engine beneath Elasticsearch) starts struggling with memory management and cluster rebalancing if shards grow larger than 50GB. If you do not roll over, your cluster will eventually throw out-of-memory errors and collapse under its own weight.
4. Applying and Monitoring ILM Policies in Production
The Problem
We have a policy (company_logs_policy). We understand aliases and rollovers. But how do we actually wire this all together so that tomorrow, when a new index rolls over, it automatically inherits the right settings?
The Definition
An Index Template is a set of rules that automatically applies mappings, settings, and ILM policies to any newly created index that matches a specific naming pattern (e.g., logs-*).
Step-by-Step Production Setup
Step 1: Create the Index Template
We tell Elasticsearch: "Whenever an index starting with logs- is created, attach our ILM policy to it, and tell it to use logs_write as its rollover alias."
PUT _index_template/logs_template
{
"index_patterns": ["logs-*"],
"template": {
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1,
"index.lifecycle.name": "company_logs_policy",
"index.lifecycle.rollover_alias": "logs_write"
}
}
}Step 2: Bootstrap the First Index
Elasticsearch needs a starting point. We have to manually create the very first index (logs-000001) and manually attach the logs_write alias to it so it knows it is the active write index.
PUT logs-000001
{
"aliases": {
"logs_write": {
"is_write_index": true
}
}
}That's it! Your application can now start sending data to logs_write.POST logs_write/_doc
ILM will silently watch the index in the background. Every 10 minutes (the default ILM poll interval), Elasticsearch checks if logs-000001 has hit 50GB or 3 days old.
Monitoring ILM
In production, things occasionally go wrong. Maybe your warm nodes ran out of disk space, so the index couldn't transition from Hot to Warm.
You can ask Elasticsearch to explain exactly what ILM is doing with an index at this exact millisecond:
GET logs-000001/_ilm/explainExpected Output (Truncated for brevity):
{
"indices": {
"logs-000001": {
"index": "logs-000001",
"managed": true,
"policy": "company_logs_policy",
"phase": "hot",
"action": "rollover",
"step": "check-rollover-ready",
"age": "1.5d"
}
}
}If something is broken, the step will usually say ERROR, and Elasticsearch will provide a step_info block detailing exactly why it failed (e.g., "no nodes found with attribute [data: warm]").
Extra Reading & References
Keep expanding your knowledge with the official Elasticsearch documentation:
- Elasticsearch ILM Overview
- Rollover API
- Data Streams (Note: Data Streams are a modern, highly automated wrapper around the Alias + Rollover pattern taught in this guide. Once you understand Aliases, Data Streams are a breeze to pick up!)
- ILM Explain API
Challenge
You are a DevOps engineer tasked with setting up a robust logging infrastructure using Elasticsearch. To prevent uncontrolled index growth and manage costs, you must implement a complete Index Lifecycle Management (ILM) policy for incoming application logs.
Your task is to write the three necessary Elasticsearch API request bodies to configure this setup from scratch.
Requirements:
ILM Policy: Create an ILM policy named
app_logs_policywith the following lifecycle:- Hot Phase: The active index should roll over when it reaches 50GB or becomes 7 days old.
- Warm Phase: After 30 days, the index should move to the warm phase. Upon entering this phase, it must be shrunk to a single primary shard and force-merged into a single segment to save space.
- Delete Phase: The index must be permanently deleted 365 days after it was rolled over.
Index Template: Create an index template named
app_logs_templatethat automatically applies the ILM configuration to all new log indices.- The template must apply to any index matching the pattern
app-logs-*. - It must associate the
app_logs_policywith matching indices. - It must define
app-logs-writeas the rollover alias.
- The template must apply to any index matching the pattern
Bootstrap Index: Create the first index,
app-logs-000001, and configure it to be the active write index for the rollover alias.- The alias must be
app-logs-write. - This alias must be explicitly marked as the
writeindex.
- The alias must be
Expected result
Your submission should consist of three complete and valid JSON objects that satisfy the requirements for the policy, template, and initial index.
Part 1: ILM Policy
The first JSON object should define the app_logs_policy. It must have a policy key containing a phases object. This phases object should define the hot, warm, and delete phases with their respective min_age, actions, and conditions (max_size, max_age).
{
"policy": {
"phases": {
"hot": {
"actions": {
"rollover": {
"max_size": "50gb",
"max_age": "7d"
}
}
},
"warm": {
"min_age": "30d",
"actions": {
"shrink": {
"number_of_shards": 1
},
"forcemerge": {
"max_num_segments": 1
}
}
},
"delete": {
"min_age": "365d",
"actions": {
"delete": {}
}
}
}
}
}Part 2: Index Template
The second JSON object should define the app_logs_template. It must specify the index_patterns to be ["app-logs-*"]. Its template.settings must contain the correct index.lifecycle.name and index.lifecycle.rollover_alias.
{
"index_patterns": ["app-logs-*"],
"template": {
"settings": {
"index.lifecycle.name": "app_logs_policy",
"index.lifecycle.rollover_alias": "app-logs-write"
}
}
}Part 3: Bootstrap Index
The third JSON object for creating the initial index app-logs-000001 must include an aliases block. This block should define the app-logs-write alias and set the is_write_index property to true.
{
"aliases": {
"app-logs-write": {
"is_write_index": true
}
}
}