How do we know replication status in elasticsearch?

11,926

Solution 1

The quickest way to check to see that all shards have been successfully replicated is the cluster health api: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-health.html

A status of "green" will tell you that all shards have allocated:

The cluster health status is: green, yellow or red. On the shard level, a red status indicates that the specific shard is not allocated in the cluster, yellow means that the primary shard is allocated but replicas are not, and green means that all shards are allocated. The index level status is controlled by the worst shard status. The cluster status is controlled by the worst index status.

It has a built in mechanism to wait for status to change and then notify you. As an example:

curl -XGET 'http://localhost:9200/_cluster/health?wait_for_status=green&timeout=60s'

will check to see if status is green. If yes it will return immediately, if not it will wait for up to 60 seconds while checking and then return status. You can call this api in a loop, or just set the timeout to a high number, and it will return when the status has changed to green, letting you know that all shards have been allocated.

Solution 2

In addition to John Petrone's answer, I would prefer using the below command

http://localhost:9200/_cat/shards/twitterindex?v

This will enlist the status of all the shards primary or replica specific to the index. Shards which are in "INITIALIZING" state are in process whereas which are marked as "STARTED" means they are successfully replicated.

Share:
11,926
Yasaswani
Author by

Yasaswani

Updated on June 07, 2022

Comments

  • Yasaswani
    Yasaswani almost 2 years

    I have set up elastic-search cluster with a single node(node1) and indexed data. After indexing is complete on the node1, another node(node2) is added to the cluster. Now I have configured the number of replicas to 1. The replication is completed successfully. But how do we know that replication is complete? Is there any API available which returns the replication status like In progress, complete.. .

    My requirement is that I should be notified when the replication is complete.