As you know the data in an index is split across one or more shards. By splitting your data across multiple shards, Elasticsearch can scale beyond what a single machine can do. Elasticsearch is a distributed system, and system failures are bound to happen. Since each shard is an independent Lucene index that can live on any node in the cluster, Elasticsearch provides a way to maintain a copy of the primary shard in a different node of the cluster. In case the node containing the primary shard fails, the replica shard (copy), which exists in a different node, is promoted to primary. For more information, please refer to the Failure Handling section in Chapter 1, Introduction to Elasticsearch.
In this section, we will talk about how the data between primary and replica is synchronized:
Let's say we have a cluster of two nodes as shown in the preceding...