Yasaswani
Yasaswani

Reputation: 117

How do we know replication status in elasticsearch?

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.

Upvotes: 7

Views: 16487

Answers (3)

Binita Bharati
Binita Bharati

Reputation: 5898

In case someone would like to check replication status per index:

curl -XGET 'http://localhost:9200/_cat/indices/<indexName>?format=json' can be used.

The response of this API contains the index health attribute. The value of this attribute will be green if replication is complete, else it will be yellow.

Upvotes: 0

user1432155
user1432155

Reputation: 733

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.

Upvotes: 13

John Petrone
John Petrone

Reputation: 27497

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.

Upvotes: 5

Related Questions