标签:生命周期 -- ilm 索引 ElasticSearch TTL policy 7.8 ES
背景
有些索引数据作为临时数据存放,一段时间后我们希望索引可以自动过期删除,就是常说的TTL(Time To Live)机制
ElasticSearch索引数量过多会占用很多主分片和副本分片,最终导致可用分片数量为0,不能再创建新的索引
这里说明一下,我们用的ElasticSearch版本为7.8.0
官方文档
关于如何管理索引的生命周期策略,官方文档有详细的描述,英语基础能力好的同学可以自行研读官方wiki
Elasticsearch7.8 生命周期策略配置
https://www.elastic.co/guide/en/elasticsearch/reference/7.8/set-up-lifecycle-policy.html
Elasticsearch7.8 开启生命周期管理
https://www.elastic.co/guide/en/elasticsearch/reference/7.8/start-stop-ilm.html
Elasticsearch7.8 查询生命周期策略
https://www.elastic.co/guide/en/elasticsearch/reference/7.8/ilm-get-lifecycle.html
启用索引生命周期管理策略
curl -u 用户名:密码 --location --request POST http://127.0.0.1:9200/_ilm/start
创建Elasticsearch生命周期策略,TTL时间1小时
curl -u 用户名:密码 --location --request PUT http://127.0.0.1:9200/_ilm/policy/index_ttl_one_hours_policy --header "Content-Type: application/json" --data-raw "{\"policy\":{\"phases\":{\"delete\":{\"min_age\":\"1h\",\"actions\":{\"delete\":{}}}}}}"
查看已创建的生命周期管理策略
curl -u 用户名:密码 --request GET http://127.0.0.1:9200/_ilm/policy
调用客户端创建引用生命周期策略的索引
public boolean createIndex() throws IOException { String indexName = "test_index"; Settings settings = Settings.builder().put("index.lifecycle.name", "index_ttl_one_hours_policy").build(); CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName); createIndexRequest.settings(settings); CreateIndexResponse indexResponse = EsRestClientCache.getEsClient(EsConstants.DEFAULT).indices().create(createIndexRequest, RequestOptions.DEFAULT); log.info("CreateIndexResponse:" + indexResponse); return indexResponse.isAcknowledged(); }
ElasticSearch生命周期策略时间单位
d - Days
h - Hours
m - Minutes
s - Seconds
ms - Milliseconds
micros - Microseconds
nanos - Nanoseconds
标签:生命周期,--,ilm,索引,ElasticSearch,TTL,policy,7.8,ES 来源: https://www.cnblogs.com/changxy-codest/p/15624292.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。