处理 Red 状态的 ES 索引
GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state
1
2
| ops-pod-loggie-2026.06.11 0 p UNASSIGNED NODE_LEFT
ops-pod-loggie-2026.06.11 0 r UNASSIGNED ALLOCATION_FAILED
|
尝试重新分配
1
| POST _cluster/reroute?retry_failed=true
|
或者直接删除
1
| DELETE ops-pod-loggie-2026.06.11
|
定时清理索引
全部索引仅保留 7 天
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| PUT _ilm/policy/ops-delete-after-7d
{
"policy": {
"phases": {
"hot": {
"actions": {}
},
"delete": {
"min_age": "7d",
"actions": {
"delete": {}
}
}
}
}
}
|
1
2
3
4
5
6
7
8
9
10
| PUT _index_template/ops-delete-after-7d
{
"index_patterns": ["*", "-.*"],
"priority": 1,
"template": {
"settings": {
"index.lifecycle.name": "ops-delete-after-7d"
}
}
}
|
1
2
3
4
| PUT /*,-.*/_settings
{
"index.lifecycle.name": "ops-delete-after-7d"
}
|
清理全部索引
1
2
3
4
5
6
| PUT _cluster/settings
{
"transient": {
"action.destructive_requires_name": false
}
}
|
1
2
3
4
5
6
| PUT _cluster/settings
{
"transient": {
"action.destructive_requires_name": true
}
}
|
清理索引
1
2
3
4
5
6
7
8
9
10
11
| USER="elastic"
PASS=""
URL="http://localhost:9200"
REFINE="ops-*"
INDICES=$(curl -s -u "$USER:$PASS" "$URL/_cat/indices/$REFINE?h=index")
for index in $INDICES; do
echo "del: $index"
curl -s -u "$USER:$PASS" -X DELETE "$URL/$index"
done
|