DBAtlas · データベース運用アトラス

シャードが多すぎるインデックスを縮小する (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"
  }
}

概要

書き込みが行われなくなったインデックスのセグメントを新しいインデックスにハードリンクして、プライマリシャード数を減らす。ヒープとシャード数のオーバーヘッドを下げる。

使用する場面

日次インデックスが必要以上のシャード数で作成された場合、シャード数の上限に近づいている場合、または古いインデックスを warm 層に移す前に。

注意

shrink 中、ソースインデックスは書き込みに対して閉じられるため、書き込みが行われなくなったインデックスにのみ適用する。対象のシャード数はソースのシャード数の約数である必要がある (8 -> 4、2、または 1)。すべてのコピーが集められるノードには、ソースインデックスと同じだけの空きディスクが必要。replicas 0 ではソースシャードのコピーは 1 つしかないため、操作が完了して新しいインデックスが green になるまでソースを削除しない。

DBAtlas で開く →

関連項目