# Index lifecycle management (ILM)
###### tags: `Elasticsearch`
>官方文件 https://www.elastic.co/guide/en/elasticsearch/reference/current/overview-index-lifecycle-management.html#overview-index-lifecycle-management :arrow_left:
>實作教學參考影片
https://52movs.com/mov/50175109.php:arrow_left:
### Index lifecycle policies can trigger actions such as:
Rollover - Redirect an index alias to begin writing to a new index when the existing index reaches a certain size, number of docs, or age.
Shrink - Reduce the number of primary shards in an index.
Force merge - Manually trigger a merge to reduce the number of segments in each shard of an index and free up the space used by deleted documents.
Freeze - Make an index read-only and minimize its memory footprint.
Delete - Permanently remove an index, including all of its data and metadata.
### As an index ages, it moves through four possible phases:
Hot—the index is actively being updated and queried.
Warm—the index is no longer being updated, but is still being queried.
Cold—the index is no longer being updated and is seldom queried. The information still needs to be searchable, but it’s okay if those queries are slower.
Delete—the index is no longer needed and can safely be deleted.

## :memo: 運作流程








## :memo: Create a lifecycle policy
生命週期策略控制索引如何在階段之間移動以及在每個階段執行什麼操作。您可以指定:
您想移到新索引的最大大小或年齡。
不再更新索引的點,可以減少主分片的數量。
何時強制合併以永久刪除標記為刪除的文檔。
可以將索引移至性能較低的硬件的位置。
可用性不那麼關鍵,可以減少副本數量。
何時可以安全刪除索引。
例如,如果您要將來自一組ATM的指標數據索引到Elasticsearch中,則可以定義一個策略,其中指出:
當索引達到50GB時,將鼠標移至新索引。
將舊索引移到暖機階段,將其標記為只讀,然後將其縮小為單個碎片。
7天后,將索引移至冷態,然後將其移至較便宜的硬件上。
達到所需的30天保留期後,刪除索引
