Shrink
editShrink
editPhases allowed: hot, warm.
Sets an index to read-only
and shrinks it into a new index with fewer primary shards.
The name of the new index is of the form shrink-<original-index-name>
.
For example, if the name of the source index is logs,
the name of the shrunken index is shrink-logs.
The shrink action allocates all primary shards of the index to one node so it can call the Shrink API to shrink the index. After shrinking, it swaps aliases that point to the original index to the new shrunken index.
To use the shrink
action in the hot
phase, the rollover
action must be present.
If no rollover action is configured, ILM will reject the policy.
If the shrink action is used on a follower index, policy execution waits until the leader index rolls over (or is otherwise marked complete), then converts the follower index into a regular index with the unfollow action before performing the shrink operation.
If the managed index is part of a data stream, the shrunken index replaces the original index in the data stream.
This action cannot be performed on a data stream’s write index. Attempts to do so will fail. To shrink the index, first manually roll over the data stream. This creates a new write index. Because the index is no longer the stream’s write index, the action can resume shrinking it. Using a policy that makes use of the rollover action in the hot phase will avoid this situation and the need for a manual rollover for future managed indices.
Shrink options
edit-
number_of_shards
-
(Optional, integer)
Number of shards to shrink to.
Must be a factor of the number of shards in the source index. This parameter conflicts with
max_primary_shard_size
, only one of them may be set. -
max_primary_shard_size
-
(Optional, byte units)
The max primary shard size for the target index. Used to find the optimum number of shards for the target index.
When this parameter is set, each shard’s storage in the target index will not be greater than the parameter.
The shards count of the target index will still be a factor of the source index’s shards count, but if the parameter
is less than the single shard size in the source index, the shards count for the target index will be equal to the source index’s shards count.
For example, when this parameter is set to 50gb, if the source index has 60 primary shards with totaling 100gb, then the
target index will have 2 primary shards, with each shard size of 50gb; if the source index has 60 primary shards
with totaling 1000gb, then the target index will have 20 primary shards; if the source index has 60 primary shards
with totaling 4000gb, then the target index will still have 60 primary shards. This parameter conflicts
with
number_of_shards
in thesettings
, only one of them may be set.
Example
editSet the number of shards of the new shrunken index explicitly
editPUT _ilm/policy/my_policy { "policy": { "phases": { "warm": { "actions": { "shrink" : { "number_of_shards": 1 } } } } } }
Calculate the optimal number of primary shards for a shrunken index
editThe following policy uses the max_primary_shard_size
parameter to
automatically calculate the new shrunken index’s primary shard count based on
the source index’s storage size.
PUT _ilm/policy/my_policy { "policy": { "phases": { "warm": { "actions": { "shrink" : { "max_primary_shard_size": "50gb" } } } } } }