샤드가 너무 많은 인덱스 shrink
Elasticsearch인덱스 수명 주기명령어
# 1) Block writes on the source and gather all shard copies on one node:
PUT log-2026.09/_settings
{
"index.number_of_replicas": 0,
"index.routing.allocation.require._name": "node-1",
"index.blocks.write": true
}
GET _cluster/health/log-2026.09?wait_for_no_relocating_shards=true&timeout=30m
# 2) Create a new index with fewer shards (the target must be a factor of the source):
POST log-2026.09/_shrink/log-2026.09-shrunk
{
"settings": {
"index.number_of_shards": 1,
"index.number_of_replicas": 1,
"index.routing.allocation.require._name": null,
"index.blocks.write": null,
"index.codec": "best_compression"
}
}하는 일
더 이상 쓰기가 없는 인덱스의 segment를 새 인덱스로 hard-link하여 primary 샤드 수를 줄인다. heap과 샤드 수 오버헤드를 낮춘다.
사용 시점
일일 인덱스가 필요 이상의 샤드로 생성되었을 때, 샤드 수 한도에 가까울 때, 또는 오래된 인덱스를 warm tier로 옮기기 전.
주의
shrink 중 원본 인덱스는 쓰기가 닫히므로 더 이상 쓰기가 없는 인덱스에만 적용한다. 대상 샤드 수는 원본 수의 약수여야 한다(8 -> 4, 2 또는 1). 모든 사본이 모이는 노드에는 원본 인덱스만큼의 여유 디스크가 필요하다. replicas 0이면 원본 샤드의 사본이 하나뿐이므로 작업이 끝나고 새 인덱스가 green이 될 때까지 원본을 삭제하지 않는다.