0
0
Elasticsearchquery~10 mins

Index settings (shards, replicas) in Elasticsearch - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Index settings (shards, replicas)
Create Index Request
Set number_of_shards
Set number_of_replicas
Elasticsearch Distributes Shards
Index Ready for Use
When creating an index, you set how many shards and replicas it has. Elasticsearch then distributes these shards across nodes.
Execution Sample
Elasticsearch
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 2
  }
}
This JSON sets an index with 3 primary shards and 2 replicas for each shard.
Execution Table
StepActionSetting ChangedValueEffect
1Create index request receivednonenoneStart index creation
2Set number_of_shardsnumber_of_shards3Index will have 3 primary shards
3Set number_of_replicasnumber_of_replicas2Each primary shard will have 2 replicas
4Elasticsearch distributes shardsshard allocation3 primaries + 6 replicasShards spread across nodes
5Index readynonenoneIndex can accept data and queries
💡 Index creation completes after shards and replicas are allocated
Variable Tracker
VariableStartAfter Step 2After Step 3Final
number_of_shardsundefined333
number_of_replicasundefinedundefined22
total_shardsundefinedundefinedundefined9 (3 primaries + 6 replicas)
Key Moments - 2 Insights
Why do we set number_of_shards before number_of_replicas?
Because replicas are copies of primary shards, you must first decide how many primary shards exist (see execution_table steps 2 and 3).
What happens if number_of_replicas is set to 0?
No replicas are created, so data is only on primary shards. This reduces fault tolerance (not shown in this trace but implied after step 3).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of number_of_shards after step 2?
A3
B2
Cundefined
D9
💡 Hint
Check the 'Setting Changed' and 'Value' columns at step 2 in execution_table
At which step does Elasticsearch distribute shards across nodes?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look for 'Elasticsearch distributes shards' in the Action column of execution_table
If number_of_replicas was set to 1 instead of 2, what would be the total shards allocated?
A3
B6 (3 primaries + 3 replicas)
C6
D9
💡 Hint
Refer to variable_tracker's total_shards calculation and adjust replicas accordingly
Concept Snapshot
Index settings control data distribution.
number_of_shards sets primary pieces.
number_of_replicas sets copies for fault tolerance.
Total shards = primaries + replicas.
Set shards first, then replicas.
Elasticsearch spreads shards across nodes.
Full Transcript
When creating an Elasticsearch index, you specify settings for number_of_shards and number_of_replicas. First, the number_of_shards is set, which determines how many primary pieces the data is split into. Then, number_of_replicas is set, which defines how many copies of each primary shard exist for safety. Elasticsearch then distributes these shards and replicas across the cluster nodes. The total shards equal the sum of primary shards and their replicas. This process ensures data is balanced and fault tolerant.