Lav
Lav

Reputation: 1047

How to remove a node from an Elasticsearch cluster at runtime without downtime

Suppose I had five nodes in a cluster and I had to remove two nodes at run time. So how can it be done without affecting the indices?

I had a continuous stream of data coming at nearly 10 Gb/hour which is getting indexed continuously.

Would rebalancing be a help in this?

Upvotes: 81

Views: 85210

Answers (2)

Ajeet Khan
Ajeet Khan

Reputation: 9190

To remove an Elasticsearch node from the cluster. Just run the following command:

curl -XPUT P.P.P.P:9200/_cluster/settings -H 'Content-Type: application/json' -d '{
  "transient" :{
      "cluster.routing.allocation.exclude._ip" : "X.X.X.X"
   }
}';echo

Here P.P.P.P is the private IP address of the master node. You may also use the localhost if Elasticsearch is running on localhost. X.X.X.X is the private IP address of the node to be removed from the cluster.

This command will give acknowledgement true if the node is accepted to be removed and the data relocation will start. Check if the data relocation is over and the node doesn't have any shards left on it. Then stop the elasticsearch process and stop/terminate the instance.

The commands to check data relocation and shards left can be found in this article.

Upvotes: 11

towr
towr

Reputation: 4167

You can decommission a node by telling the cluster to exclude it from allocation. (From the documentation here)

curl -XPUT localhost:9200/_cluster/settings -H 'Content-Type: application/json' -d '{
  "transient" :{
      "cluster.routing.allocation.exclude._ip" : "10.0.0.1"
   }
}';echo

This will cause Elasticsearch to allocate the shards on that node to the remaining nodes, without the state of the cluster changing to yellow or red (even if you have replication 0).

Once all the shards have been reallocated you can shutdown the node and do whatever you need to do there. Once you're done, include the node for allocation and Elasticsearch will rebalance the shards again.

Upvotes: 151

Related Questions