概要
ElasticSearch中的索引生命周期管理,也就是ilm(Manage the index lifecycle),是指定了索引在不同周期下的处理策略。 ilm 的对象是索引而不是索引中的数据。 ilm 包括四个阶段:hot 、warm、cold和delete。 hot、warm和cold表示索引的使用情况,delete可以指定索引完成rollover后的旧索引的删除条件。 hot中常用策略为 rollover, 满足指定条件后创建新的索引。 delete中常用属性为min_age,也就是索引完成rollover后的删除策略。已经有可以提供相同功能的索引,就索引可以删除。 索引生命周期中的delete不能删除索引,只能删除滚动之前的旧索引。
使用命令
GET _ilm/ policy
GET _ilm/ policy/ < policy- name>
GET < index- name> / _ilm/ explain
GET / _cat/ indices/ < index- name> ? format= json& h= index, creation. date
DELETE策略执行分析
先查询索引的创建时间。
GET / _cat/ indices/ < index- name> ? format= json& h= index, creation. date`
[ { "index" : "<index-name>" , "creation.date" : "1688537411543" }
]
在查询索引的中生命周期的执行情况
GET < index- name> / _ilm/ explain
{ "indices" : { "<index-name>" : { ... "policy" : "<policy-name>" , "lifecycle_date_millis" : 1691129648787 , "age" : "3.87d" , ... } , ... } }
}
生命周期策略的具体信息
GET _ilm/ policy/ < policy- name>
{ "<policy-name>" : { ... "policy" : { "phases" : { "hot" : { "min_age" : "0ms" , "actions" : { "rollover" : { "max_primary_shard_size" : "50gb" , "max_age" : "30d" } } } , "delete" : { "min_age" : "30d" , "actions" : { "delete" : { "delete_searchable_snapshot" : true } } } } , ... } , "in_use_by" : { "indices" : [ ... ] , ... } }
}
所以整个流程为索引超过30天后,会自动rollover出个新的索引,之后按照delete策略删除旧的索引。所以生命周期不会自动删除索引,索引的删除需要手动执行。