索引生命周期管理
使用 ILM 策略自动管理索引经历热、温、冷和删除阶段的生命周期,在大规模场景下控制成本与性能。
索引生命周期管理 是 CoddyKit 上的免费 Elasticsearch & Full Text Search Systems 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Elasticsearch & Full Text Search Systems 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Elasticsearch & Full Text Search Systems 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Data Gets Old
Time-based data like logs and metrics keeps growing. Recent data is queried constantly; old data rarely. Index Lifecycle Management (ILM) automates moving indices through phases so you spend resources only where they matter.
The Four Phases
ILM defines up to four phases:
- Hot: actively written and queried.
- Warm: no longer written, still queried.
- Cold: rarely queried, kept cheaply.
- Delete: removed.
Rollover
In the hot phase, rollover starts a fresh index when the current one hits a size, document count, or age limit. This keeps individual shards a manageable size.
"rollover": {
"max_size": "50gb",
"max_age": "7d"
}Defining a Policy
An ILM policy lists each phase and its min_age and actions. Here data moves to warm after 7 days and is deleted after 30.
PUT _ilm/policy/logs_policy
{
"policy": { "phases": {
"hot": { "actions": { "rollover": { "max_age": "1d" } } },
"warm": { "min_age": "7d", "actions": {} },
"delete": { "min_age": "30d", "actions": { "delete": {} } }
}}
}Warm Phase Actions
In warm you can shrink the index to fewer shards, forcemerge segments for query efficiency, and move shards to cheaper warm nodes via allocation.
"warm": {
"actions": {
"forcemerge": { "max_num_segments": 1 },
"shrink": { "number_of_shards": 1 }
}
}Cold and Frozen
The cold phase can store data as searchable snapshots on object storage, drastically cutting cost while keeping it queryable. The frozen tier takes this even further for archival data.
Attaching to an Index
A policy is linked to indices through an index template, so newly rolled-over indices inherit it automatically.
PUT _index_template/logs_template
{
"index_patterns": ["logs-*"],
"template": { "settings": {
"index.lifecycle.name": "logs_policy"
}}
}Data Streams
Data streams are the modern way to manage append-only time-series data with ILM. They hide rollover behind a single write alias, so you just index into the stream name.
Monitoring ILM
Use the explain lifecycle API to see which phase each index is in and whether any step is stuck or errored.
GET logs-*/_ilm/explainCost and Performance Wins
ILM lets hot data live on fast SSD nodes while old data drifts to cheap storage and is eventually deleted automatically. This is the backbone of cost-effective, large-scale time-series clusters.
Best Practices
Roll over on size to keep shards near 30-50 GB, forcemerge only once writes stop, test policies on a sample index, and always pair ILM with snapshots for true backups (delete is permanent).
Quick Check
Test your understanding of ILM.
Recap
You learned to automate index aging:
- ILM moves indices through hot, warm, cold, and delete phases by age.
- Rollover keeps shards manageable; warm actions shrink and forcemerge.
- Cold/frozen tiers use searchable snapshots for cheap storage.
- Attach policies via templates, use data streams for time-series, and pair ILM with real snapshots.
用 AI 导师学习 Elasticsearch & Full Text Search Systems — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 12
- 课程
- 48
常见问题解答
「索引生命周期管理」课时是免费的吗?
是的 — 「索引生命周期管理」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Elasticsearch & Full Text Search Systems 课程的其余内容,请升级到 CoddyKit PRO。 Elasticsearch & Full Text Search Systems 课程共包含 4 节课。
「索引生命周期管理」这节课中我会学到什么?
使用 ILM 策略自动管理索引经历热、温、冷和删除阶段的生命周期,在大规模场景下控制成本与性能。 你通过在浏览器中直接运行的动手代码来练习 Elasticsearch & Full Text Search Systems,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Elasticsearch & Full Text Search Systems 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Elasticsearch & Full Text Search Systems 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「索引生命周期管理」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Elasticsearch & Full Text Search Systems 课中编写并运行代码吗?
能。每节 Elasticsearch & Full Text Search Systems 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。