0
0
Elasticsearchquery~5 mins

Replica management in Elasticsearch

Choose your learning style9 modes available
Introduction

Replica management helps keep copies of your data to make your search faster and your data safer.

You want your search to be faster by using copies of data.
You want to protect your data in case one copy breaks.
You want to balance the load when many users search at the same time.
You want to keep your system working even if some parts fail.
Syntax
Elasticsearch
PUT /my_index
{
  "settings": {
    "number_of_replicas": 2
  }
}

Use number_of_replicas to set how many copies of your data you want.

You can change replicas anytime to add or remove copies.

Examples
This creates an index named products with 1 replica copy.
Elasticsearch
PUT /products
{
  "settings": {
    "number_of_replicas": 1
  }
}
This changes the logs index to have no replicas, meaning only one copy of data.
Elasticsearch
PUT /logs/_settings
{
  "settings": {
    "number_of_replicas": 0
  }
}
This command shows the current number of replicas for my_index.
Elasticsearch
GET /my_index/_settings
Sample Program

This example creates an index called library with 2 replicas, then checks the settings to confirm.

Elasticsearch
PUT /library
{
  "settings": {
    "number_of_replicas": 2
  }
}

GET /library/_settings
OutputSuccess
Important Notes

More replicas mean better search speed and safety but use more storage space.

Zero replicas means no copies, so if data breaks, it can be lost.

You can update replicas without stopping your Elasticsearch service.

Summary

Replica management controls how many copies of your data exist.

Replicas improve search speed and data safety.

You can set or change replicas anytime using index settings.