Elasticsearch is designed to be a distributed system that can handle a large amount of data and provide high availability. One of the key features that enable this is the concept of index replication, which is controlled by the number_of_replicas
setting. This article will delve into the details of this setting, its implications, and how to properly configure it.
The role of replicas in Elasticsearch
In Elasticsearch, an index is a collection of documents that are partitioned across multiple primary shards. Each primary shard is a self-contained Apache Lucene index, and the documents within an index are distributed among all primary shards. To ensure high availability and data redundancy, Elasticsearch allows each shard to have one or more copies, known as replicas.
The number_of_replicas
setting controls the number of replica shards (copies) that Elasticsearch creates for each primary shard in an index. By default, Elasticsearch creates one replica for each primary shard, but this can be changed according to the requirements of your system.
Configuring the number_of_replicas
The number_of_replicas
setting can be configured at the time of index creation or updated later. Here’s how you can set it during index creation:
PUT /my_index
{
"settings": {
"number_of_replicas": 2
}
}
In this example, Elasticsearch will create two replicas for each primary shard in the my_index
index.
To update the number_of_replicas
setting for an existing index, you can use the _settings
API:
PUT /my_index/_settings
{
"number_of_replicas": 3
}
This command will update the my_index
index to have three replicas for each primary shard.
Implications of the number_of_replicas setting
The number_of_replicas
setting has a significant impact on the performance and resilience of your Elasticsearch cluster. Here are some key points to consider:
- Data Redundancy and Availability: Increasing the
number_of_replicas
enhances the availability of your data by creating more copies of each shard. If a node fails, Elasticsearch can still serve data from the replica shards on the remaining nodes. - Search Performance: Replica shards can serve read requests, so having more replicas can improve search performance by distributing the load across more shards.
- Write Performance: However, each write operation must be performed on every copy of a shard. Therefore, a higher
number_of_replicas
can slow down indexing performance as it increases the number of operations that must be performed for each write. - Storage Requirements: More replicas mean more storage space. You should ensure that your cluster has enough capacity to store the additional replicas.
- Resilience to Node Failure: The
number_of_replicas
should be set considering the number of nodes in your cluster. If thenumber_of_replicas
is equal to or greater than the number of nodes, your cluster can tolerate the failure of multiple nodes without data loss.
Best practices for setting number_of_replicas
The optimal number_of_replicas
setting depends on the specific requirements of your system. However, here are some general best practices:
- For a single-node cluster,
number_of_replicas
should be set to 0, as there are no other nodes to hold replicas. - For a multi-node cluster,
number_of_replicas
should be set to at least 1 to ensure data redundancy and high availability. - If search performance is a priority, consider increasing the
number_of_replicas
. However, keep in mind the trade-off with write performance and storage requirements. - Always ensure that your cluster has enough capacity to store the additional replicas.
Ready to try this out on your own? Start a free trial.
Want to get Elastic certified? Find out when the next Elasticsearch Engineer training is running!
Related content

October 20, 2025
How to deploy Elasticsearch on an Azure Virtual Machine
Learn how to deploy Elasticsearch on Azure VM with Kibana for full control over your Elasticsearch setup configuration.

How to use the Synonyms UI to upload and manage Elasticsearch synonyms
Learn how to use the Synonyms UI in Kibana to create synonym sets and assign them to indices.

October 8, 2025
How to reduce the number of shards in an Elasticsearch Cluster
Learn how Elasticsearch shards affect cluster performance in this comprehensive guide, including how to get the shard count, change it from default, and reduce it if needed.

October 3, 2025
How to deploy Elasticsearch on AWS Marketplace
Learn how to set up and run Elasticsearch using Elastic Cloud Service on AWS Marketplace in this step-by-step guide.

September 29, 2025
HNSW graph: How to improve Elasticsearch performance
Learn how to use the HNSW graph M and ef_construction parameters to improve search performance.