文档中心 Elasticsearch服务 最佳实践 索引生命周期管理ilm 应用策略到索引

应用策略到索引

最近更新时间:2021-03-03 16:34:28

本文介绍应用策略到索引的两种方式。

第一种方式

curl -X PUT "localhost:9200/_template/my_template?pretty" -H 'Content-Type: application/json' -d'
{
  "index_patterns": ["test-*"], 
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1,
    "index.lifecycle.name": "my_policy", 
    "index.lifecycle.rollover_alias": "test-alias"
  }
}
'

满足这个模板的新建索引会自动应用策略my_policy,如果策略中包含rollover,还需要初始化索引。

curl -X PUT "localhost:9200/test-000001?pretty" -H 'Content-Type: application/json' -d'
{
  "aliases": {
    "test-alias":{
      "is_write_index": true 
    }
  }
}
'

第二种方式(前提是不包含rollover)

curl -X PUT "localhost:9200/test-index?pretty" -H 'Content-Type: application/json' -d'
{
  "settings": {
    "index.lifecycle.name": "my_policy"
  }
}
'

查看集群当前的ilm策略:

curl -XGET localhost:9200/_ilm/policy?pretty

查看索引test-index生命周期管理执行的状态:

curl -XGET localhost:9200/test-index/_ilm/explain?pretty

上一篇:创建策略
下一篇:通过Kibana配置ilm
以上内容是否对您有帮助?
有帮助
没帮助