点击上方“IT那活儿”,关注后了解更多精彩内容!!!
ES生命周期管理简介
生命周期策略
PUT _ilm/policy/test_policy{"policy": {"phases": {"hot": {"actions": {"rollover":{"max_docs":1},"set_priority": {"priority": 100}}},"delete": {"min_age": "30s","actions": {"delete": {}}}}}}

当在生命周期策略处理中出现异常时,会进入错误阶段,停止策略的执行。
GET /myindex/_ilm/explain
使用上述API可以看到异常的原因,当解决这个问题,并更新策略后,可以通过下面的API进行重试:
POST /myindex/_ilm/retry
ilm的状态查看:
GET _ilm/status
开启和关闭:
POST _ilm/startPOST _ilm/stop
实验环境

实验步骤
curl -H 'Content-Type: application/json' -XPUT -u elastic:qwer123 -s http://@192.168.43.139:9200/_ilm/policy/test_policy -d'{"policy": {"phases": {"hot": {"actions": {"rollover":{"max_docs":1,"max_age": "90s"},"set_priority": {"priority": 100}}},"delete": {"min_age": "180s","actions": {"delete": {}}}}}}'
查看生命周期策略:
curl -XGET -u elastic:qwer123 -shttp://@192.168.43.139:9200/_ilm/policy/test_policy?pretty

curl -H 'Content-Type: application/json' -XPUT -u elastic:qwer123 -s http://@192.168.43.139:9200/_template/datastream_template -d'{"index_patterns": ["test-*"],"settings": {"number_of_shards": 1,"number_of_replicas": 1,"index.lifecycle.name": "test_policy","index.lifecycle.rollover_alias": "test-alias"}}'
查看创建的索引模板
curl -XGET -u elastic:qwer123 -s http://@192.168.43.139:9200/_template/test_template?pretty

curl -H 'Content-Type: application/json' -XPUT -u elastic:qwer123 -s http://@192.168.43.139:9200/_cluster/settings -d'{"transient": {"indices.lifecycle.poll_interval": "10s"}}'
curl -H 'Content-Type: application/json' -XPUT -u elastic:qwer123 -s http://@192.168.43.139:9200/test-000001 -d'{"aliases": {"test-alias": {"is_write_index": true}}}'
curl -H 'Content-Type: application/json' -XPOST -u elastic:qwer123 -s http://@192.168.43.139:9200/test-alias/_doc -d'{"message":"hello world"}'
curl -XGET -u elastic:qwer123 -s http://@192.168.43.139:9200/test-*/_ilm/explain?pretty
索引自动创建了一个新的"test-0000063",旧的索引”test-000061”,”test-0000062” action变成DELETE。

curl -XGET -u elastic:qwer123 -s http://@192.168.43.139:9200/test-*/_ilm/explain?pretty

更多精彩干货分享
点击下方名片关注
IT那活儿

文章转载自IT那活儿,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




