Elasticsearch medium
Why is it generally impossible to change the number of Primary Shards in an index without performing an expensive 'Reindex' operation?
- A The underlying Lucene directory structure is physically locked by the operating system.
- B Hashing Consistency: Document routing relies on the formula `shard = hash(_id) % number_of_primary_shards`. Changing the divisor (the shard count) would cause the hash to point to the wrong server, making all existing documents unreachable.
- C The master node cannot track more than the initial number of shards for a single index ID.
- D It requires a full license for the 'Elastic Premium' tier.
Answer: B. Hashing Consistency: Document routing relies on the formula `shard = hash(_id) % number_of_primary_shards`. Changing the divisor (the shard count) would cause the hash to point to the wrong server, making all existing documents unreachable.
Routing logic is deterministic. If you have 5 shards, ID '123' might hash to Shard 3. If you suddenly change to 6 shards, the math might point to Shard 1. Since the data is physically sitting on Shard 3, the database would 'lose' the document. Reindexing rebuilds the distribution for the new shard count.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- What are the two primary reasons for configuring one or more 'Replica Shards' for an index?
- When a String field is mapped as `text`, what process is performed to enable full-text search capability?
- What is the primary benefit of splitting an Elasticsearch index into multiple 'Primary Shards'?
- Every document stored in an Elasticsearch index is uniquely tracked by which mandatory metadata field?
- Elasticsearch search results include a metadata field called `_score`. What does this value primarily indicate?
- What is the primary architectural purpose of Elasticsearch in a modern software stack?