1.问题背景
es集群突然查询很慢,定位到是查询近360天指标索引时,查询量太大导致的,每天三四百万流水,频繁查询把数据变成了热点数据,加载到内存中,导致内存不断增大,最终被撑爆,报data too large的错误。
2.临时解决方案
因为是指标,所以允许为空,后续再重新计算,补上,所以,在生产环境,我们选择了保证集群可用。因为我们是根据别名查询的,有360个索引,因此,我们选择了删掉别名,然后创建一个别名为指标索引的空索引,修改或删除完别名之后,建议通过kibana关闭索引,不要直接关闭索引,要先删除别名,不然直接关闭索引查询会报错。关闭索引可以大大减少资源消耗,特别是对不常访问或只需要保留其历史记录的索引来说。
操作命令:
#通配符批量删除索引别名(适用于索引多)
DELETE /afp_idx_2024*/_alias/afp_idx
#批量删除索引别名(适用于索引有限)
POST /_aliases
{
"actions": [
{
"remove": {
"index": "afp_idx_20230908",
"alias": "afp_idx"
}
},
{
"remove": {
"index": "afp_idx_20230909",
"alias": "afp_idx"
}
},
{
"remove": {
"index": "afp_idx_20230910",
"alias": "afp_idx"
}
}
}
#批量新增索引别名(适用于索引有限)
POST /_aliases
{
"actions": [
{
"add": {
"index": "afp_idx_20240906",
"alias": "afp_idx_back"
}
},
{
"add": {
"index": "afp_idx_20240906",
"alias": "afp_idx_back"
}
},
{
"add": {
"index": "afp_idx_20240906",
"alias": "afp_idx_back"
}
}
}
#删除新增(可以理解为修改)
POST /_aliases
{
"actions": [
{
"remove": {
"index": "afp_idx_20240906",
"alias": "afp_idx"
}
},
{
"add": {
"index": "afp_idx_20240906",
"alias": "afp_idx_back"
}
}
}
#上面的命令也可以用curl命令执行
curl -X POST "http://localhost:9200/_aliases" -H 'Content-Type: application/json' -d'
{
"actions": [
{
"remove": {
"index": "afp_idx_20240906",
"alias": "afp_idx"
}
},
{
"add": {
"index": "afp_idx_20240906",
"alias": "afp_idx_back"
}
},
{
"remove": {
"index": "afp_idx_20240905",
"alias": "afp_idx"
}
},
{
"add": {
"index": "afp_idx_20240905",
"alias": "afp_idx_back"
}
}
}'
标签:index,idx,alias,别名,---,索引,ElasticSearch,afp
From: https://www.cnblogs.com/hujunwei/p/18400174