Skip to main content
InterviewHubPRO
Section Overview
Q15

Question 15 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

30%
Elasticsearch & Lucene (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

How does Elasticsearch route a document to a specific shard?

senior LevelSystem Design

In Simple Words: When indexing a document, Elasticsearch determines the target primary shard using a hash formula: $$shard = \text{hash}(routing) \pmod{\text{number_of_primary_shards}}$$

  • By default, routing is the document's _id.
  • Custom Routing: You can pass ?routing=tenant_123 to force all documents belonging to a specific customer to live on the same shard, dramatically speeding up tenant-specific queries.