ES 生命周期管理

一 .概念

ILM定义了四个生命周期阶段:
Hot:正在积极地更新和查询索引。
Warm:不再更新索引,但仍在查询。
cold:不再更新索引,很少查询。信息仍然需要可搜索,但是如果这些查询速度较慢也可以。
Delete:不再需要该索引,可以安全地将其删除

仅仅在 Hot阶段 可以设置 rollover滚动

在实验中可以修改设置,来缩短ILM检测时间间隔。ILM定期运行(indices.lifecycle.poll_interval),默认是10分钟,检查索引是否符合策略标准,并执行所需的任何步骤

java 复制代码
PUT /_cluster/settings

{ "transient": { "indices.lifecycle.poll_interval": "1m" } }

参数的设置:满足任意一个创建新的索引

HOT

WARM

Delete

二. 实战

1 .创建生命周期策略模板:PUT 请求

http://localhost:9099/_ilm/policy/my_index_rollover_policy

"max_docs": 5000000 设置超过500万是创建新的索引,实际测试可以设置小一点

java 复制代码
{
    "policy": {
        "phases": {
            "hot": {
                "actions": {
                    "rollover": {
                        "max_docs": 5000000
                    },
                    "set_priority": {
                        "priority": 100
                    }
                }
            },
            "warm": {
                "min_age": "30d",
                "actions": {
                    "forcemerge": {
                        "max_num_segments": 1
                    },
                    "shrink": {
                        "number_of_shards": 1
                    },
                    "allocate": {
                        "number_of_replicas": 1
                    },
                    "set_priority": {
                        "priority": 50
                    }
                }
            },
            "cold": {
                "min_age": "90d",
                "actions": {
                    "freeze": {},
                    "allocate": {
                        "require": {
                            "type": "cold"
                        }
                    },
                    "set_priority": {
                        "priority": 10
                    }
                }
            },
            "delete": {
                "min_age": "3650d",
                "actions": {
                    "delete": {}
                }
            }
        }
    }
}
  1. 创建索引模板(日志统计索引) PUT 请求:

http://localhost:9099/_template/my_statistic_log

java 复制代码
{
    "index_patterns": [
        "my_statistic_log-*"
    ],
    "settings": {
        "index.number_of_shards": 5,
        "index.number_of_replicas": 1,
        "refresh_interval": "60s",
        "index.lifecycle.name": "my_index_rollover_policy",
        "index.lifecycle.rollover_alias": "statistic_log_write"
    },
    "aliases": {
        "statistic_log_read": {}
    },
    "mappings": {
        "log": {
            "dynamic": "strict",
            "_field_names": {
                "enabled": false
            },
            "dynamic_templates": [
                {
                    "date": {
                        "match": "*Date",
                        "mapping": {
                            "type": "date"
                        }
                    }
                },
                {
                    "strings": {
                        "match_mapping_type": "string",
                        "mapping": {
                            "type": "keyword"
                        }
                    }
                },
                {
                    "long_or_text": {
                        "match": "*Time",
                        "mapping": {
                            "type": "date"
                        }
                    }
                },
                {
                    "dataFormat": {
                        "match": "*Date",
                        "mapping": {
                            "type": "date"
                        }
                    }
                },
                {
                    "timeFormat": {
                        "match": "*Time",
                        "mapping": {
                            "type": "date"
                        }
                    }
                },
                {
                    "noAnalyzed": {
                        "match_mapping_type": "string",
                        "mapping": {
                            "type": "keyword"
                        }
                    }
                }
            ],
            "properties": {
                "area": {
                    "type": "keyword"
                },
                "desc": {
                    "type": "keyword"
                },
                "hour": {
                    "type": "integer"
                },
                "day": {
                    "type": "integer"
                },
                "startTime": {
                    "type": "date",
                    "format": "yyyy-MM-dd HH:mm:ss"
                },
                "totalCount": {
                    "type": "long"
                }
            }
        }
    }
}
  1. 根据索引模板创建起始索引(日志统计索引)

put 请求: http://localhost:9099/my_statistic_log-000001

java 复制代码
{
    
    "aliases": {
        "statistic_log_write": {
            "is_write_index": true
        }
    }
}
  1. 查看索引生效:GET请求

http://localhost:9099/my_statistic_log-000001/_ilm/explain

https://www.elastic.co/guide/en/elasticsearch/reference/6.8/_setting_up_a_new_policy.html

相关推荐
arvin_xiaoting1 天前
#zsh# #Ubuntu# 一键安装zsh、oh-my-zsh、常用插件
linux·ubuntu·elasticsearch
九河云1 天前
TOS + 数字孪生:集装箱码头的智能进化密码
大数据·服务器·网络·数据库·数字化转型
说私域1 天前
开源链动2+1模式AI智能名片S2B2C商城小程序在竞争激烈的中低端面膜服装行业中的应用与策略
大数据·人工智能·小程序
bemyrunningdog1 天前
IntelliJ IDEA合并分支到master全攻略
大数据·elasticsearch·intellij-idea
孟意昶1 天前
Doris专题17- 数据导入-文件格式
大数据·数据库·分布式·sql·doris
星光一影1 天前
Java版小区物业管理系统/业主端/物业端/管理端/支持公众号、小程序、app
java·大数据·小程序
武子康1 天前
大数据-125 - Flink 实时流计算中的动态逻辑更新:广播状态(Broadcast State)全解析
大数据·后端·flink
数在表哥1 天前
从数据沼泽到智能决策:数据驱动与AI融合的中台建设方法论与技术实践指南(一)
大数据·人工智能
dessler1 天前
Elasticsearch(ES)分片(Shard)和 副本分片(Replica Shard)
linux·运维·elasticsearch
还是大剑师兰特1 天前
Hadoop面试题及详细答案 110题 (71-85)-- 集群部署与运维
大数据·hadoop·大剑师·hadoop面试题