通過es索引生命周期策略刪除日志索引
在es 7.x版本之后,多了個索引生命周期的概念,可以一系列的設置,給新生成的索引綁定生命周期策略,到期后,索引自動刪除。
也可以通過linux定時任務實現(xiàn),請查看另一篇文章《通過linux定時任務刪除es日志索引》
流程
- 創(chuàng)建索引生命周期策略
- 創(chuàng)建索引模板,與生命周期策略綁定,匹配新生成的索引,關聯(lián)索引生命周期
操作
下面的操作也可以通過kibana來完成
創(chuàng)建索引生命周期策略
創(chuàng)建名稱為auto_delete_policy 索引生命周期策略,索引7天后,自動刪除。測試時,可以設置策略時間短點。
PUT /_ilm/policy/auto_delete_policy
{
"policy": {
"phases": {
"delete": {
"min_age": "7d",
"actions": {
"delete": {}
}
}
}
}
}
查詢索引生命周期策略
GET /_ilm/policy/auto_delete_policy
創(chuàng)建索引模板
索引模板作為中間橋梁,把索引生命周期策略和索引關聯(lián)起來,這里匹配 my、index 開頭,新生成的索引
PUT _template/elk_template
{
"index_patterns": [
"my*",
"index*"
],
"template": {
"settings": {
"index": {
"lifecycle": {
"name": "auto_delete_policy",
"indexing_complete": "true"
}
}
}
}
}
創(chuàng)建索引模板(elk_tempalte),index.lifecycle.name 把上面的自動刪除策略綁定到elk索引模板
后來新生成 my-、index- 開頭的索引時就會應用這個模板。
indexing_complete:true,必須設為true,跳過HOT階段的Rollover
查詢索引模板
GET _template/elk_template
測試
測試設置
生命周期策略默認10分鐘檢測一次,為了方便測試,這里設為30s。后面改回來就可以了。
PUT /_cluster/settings
{
"transient": {
"indices.lifecycle.poll_interval": "30s"
}
}
查看索引
查看新生成的索引,有沒有關聯(lián)到索引生命周期策略,
這里查看my-開頭的索引情況
GET my-*/_ilm/explain
返回文章來源:http://www.zghlxwxcb.cn/news/detail-698163.html
{
"indices": {
"my-2023.08.30": {
"index": "my-2023.08.30",
"managed": true,
"policy": "auto_delete_policy",
"lifecycle_date_millis": 1693357650166,
"age": "3.35d",
"phase": "new",
"phase_time_millis": 1693357650194,
"action": "complete",
"action_time_millis": 1693357650194,
"step": "complete",
"step_time_millis": 1693357650194,
"phase_execution": {
"policy": "auto_delete_policy",
"version": 1,
"modified_date_in_millis": 1692951002180
}
}
}
}
參考官網(wǎng)索引管理章節(jié)文章來源地址http://www.zghlxwxcb.cn/news/detail-698163.html
到了這里,關于通過es索引生命周期策略刪除日志索引的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!