ES ILM 生命周期管理

注意: 文章中所有数据都在单节点下、如果是多节点、可以单独设置冷热数据;参考其他文章;

1、设置索引生命周期管理间隔(1s、默认是1小时,主要为了测试进行修改)

PUT _cluster/settings
{
  "persistent": {
    "indices.lifecycle.poll_interval": "1s"
  }
}

2、设置生命周期

一共四个阶段:hot、warm、cold、delete

PUT _ilm/policy/my_custom_policy_filter
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "set_priority": {
            "priority": 100
          },
          "rollover": {
            "max_age": "3d",
            "max_docs": 5,
            "max_size": "5gb"
          }
        }
      },
      "warm": {
        "min_age": "15s",
        "actions": {
          "set_priority": {
            "priority": 50
          },
          "allocate": {
            "number_of_replicas": 1,
            "include": {
              "_name": "",
              "_ip": ""
            },
            "exclude": {
              "_name": "",
              "_ip": ""
            },
            "require": {
              "_name": "",
              "_ip": ""
            }
          },
          "shrink": {
            "number_of_shards": 1
          },
          "forcemerge": {
            "max_num_segments": 1
          }
        }
      },
      "cold": {
        "min_age": "30s",
        "actions": {
          "set_priority": {
            "priority": 0
          },
          "freeze": {},
          "allocate": {
            "number_of_replicas": 1,
            "include": {
              "_name": "",
              "_ip": ""
            },
            "exclude": {
              "_name": "",
              "_ip": ""
            },
            "require": {
              "_name": "",
              "_ip": ""
            }
          }
        }
      },
      "delete": {
        "min_age": "45s",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

3、创建模版、关联配置的ilm_policy

PUT _index_template/timeseries_template
{
  "index_patterns": ["timeseries-*"],
  "template":{
    "settings": {
     "number_of_replicas": 0,
     "number_of_shards": 1,
     "index.lifecycle.name": "my_custom_policy_filter",
     "index.lifecycle.rollover_alias": "timeseries"
   }
  }
}

4、创建起始索引

PUT timeseries-000001
{
  "aliases": {
    "timeseries": {
      "is_write_index": true
    }
  }
}

5、插入数据

PUT timeseries/_bulk
{"index": {"_id": 1}}
{"title": "testting 01"}
{"index": {"_id": 2}}
{"title": "testting 02"}
{"index": {"_id": 3}}
{"title": "testting 03"}
{"index": {"_id": 4}}
{"title": "testting 04"}

5.1 生成新的索引

GET timeseries-000002/_search

6、临界值 (插入第5条数据)会滚动

PUT timeseries/_bulk
{"index": {"_id": 5}}
{"title": "testting 05"}

6-1生成滚动索引

GET timeseries-000002/_search

7、在插入一条数据(写入到timeseries-000002 索引中)

PUT timeseries/_bulk
{"index": {"_id": 6}}
{"title": "testting 06"}

GET timeseries/_search

ILM(Index Lifecycle Management)是Elasticsearch提供的一种功能,用于管理索引的生命周期。ILM的目标是通过自动化索引的创建、删除和转换,以及自动化数据的热、温和冷存储来简化索引的管理。 ILM的生命周期可以分为以下几个阶段: 1. 索引创建阶段(Index Creation Phase):在此阶段,定义索引的模板并创建初始索引。可以指定索引的名称、分片和副本数等参数。 2. 热阶段(Hot Phase):在此阶段,索引处于活动状态,接收并处理实时数据。可以定义索引在何时进入热阶段并设置要保留的文档数量或时间范围。 3. 温阶段(Warm Phase):当索引进入温阶段时,可以对其进行一些优化,例如合并段、优化存储结构等,以提高查询性能。可以定义何时将索引迁移到温节点,并设置何时触发优化操作。 4. 冷阶段(Cold Phase):在冷阶段,将索引从温节点迁移到冷节点,以节省存储成本。可以定义何时将索引迁移到冷节点,并设置何时触发归档或删除操作。 5. 删除阶段(Delete Phase):在此阶段,根据设定的策略删除索引。可以根据索引的年龄、文档数量或其他条件设置何时删除索引。 ILM的配置可以通过Elasticsearch的API或者Kibana界面进行操作,可以根据需求灵活地定义和调整索引的生命周期。通过使用ILM,可以自动化和简化索引管理,提高系统的可靠性和可用性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值