- Elasticsearch 7.0 Cookbook(Fourth Edition)
- Alberto Paro
- 148字
- 2021-06-24 14:52:24
How it works...
The shrink API reduces the number of shards by executing the following steps:
- Elasticsearch creates a new target index with the same definition as the source index, but with a smaller number of primary shards.
- Elasticsearch hard-links (or copies) segments from the source index into the target index.
If the filesystem doesn't support hard-linking, then all segments are copied into the new index, which is a much more time-consuming process. Elasticsearch recovers the target index as though it were a closed index that has just been reopened. On a Linux system, the process is very fast due to hard links.
The prerequisites for executing a shrink are as follows:
- All the primary shards must be on the same node
- The target index must not exist
- The target number of shards must be a factor of the number of shards in the source index