Elasticsearch Removing a Node from an Elasticsearch Cluster

By Opster Team

Updated: Jun 6, 2023

| 2 min read

Introduction 

When managing an Elasticsearch cluster, there may be situations where you need to remove a node from the cluster. This could be due to hardware issues, maintenance, or scaling down the cluster. In this article, we will discuss the steps to safely remove a node from an Elasticsearch cluster without causing any data loss or impacting the cluster’s performance. If you want to learn about the concept of Elasticsearch nodes and the types of roles, check out this guide.

Steps to safely remove a node from an Elasticsearch cluster

Step 1: Disable shard allocation

Before removing a node, it is essential to disable shard allocation. This prevents Elasticsearch from reallocating shards to the node that is being removed during the removal process. To disable shard allocation, execute the following command:

PUT _cluster/settings
{
  "persistent": {
    "cluster.routing.allocation.enable": "none"
  }
}

Step 2: Stop indexing and perform a synced flush (optional)

If you can afford to stop indexing for a short period, it is recommended to perform a synced flush. This operation helps to speed up the recovery process when the cluster restarts after the node removal. To perform a synced flush, execute the following command:

POST _flush/synced

Note that this step is optional and can be skipped if stopping indexing is not feasible.

Step 3: Retrieve the node ID

To remove a node from the cluster, you need to know its node ID. You can retrieve the node ID by executing the following command:

GET _cat/nodes?v

This command will return a list of nodes in the cluster along with their node IDs. Identify the node you want to remove and note down its node ID.

Step 4: Remove the node from the cluster

To remove the node from the cluster, you need to update the cluster settings to exclude the node using its node ID. Execute the following command, replacing `<node_id>` with the node ID you retrieved in the previous step:

PUT _cluster/settings
{
  "persistent": {
    "cluster.routing.allocation.exclude._id": "<node_id>"
  }
}

This command will instruct Elasticsearch to move all shards from the specified node to other nodes in the cluster. You can monitor the progress of shard relocation by executing the following command:

GET _cat/recovery?v&active_only=true

Wait for the shard relocation process to complete before proceeding to the next step.

Step 5: Enable shard allocation

Once all shards have been relocated from the node you want to remove, you can enable shard allocation again. This allows Elasticsearch to allocate shards to the remaining nodes in the cluster. To enable shard allocation, execute the following command:

PUT _cluster/settings
{
  "persistent": {
    "cluster.routing.allocation.enable": "all"
  }
}

Step 6: Stop the Elasticsearch process on the node

After enabling shard allocation, you can safely stop the Elasticsearch process on the node you want to remove. Depending on your installation method and operating system, the command to stop Elasticsearch may vary. For example, if you are using systemd on a Linux system, you can execute the following command:

sudo systemctl stop elasticsearch

Step 7: Verify the cluster health

Finally, verify the health of the cluster by executing the following command:

GET _cluster/health

Ensure that the cluster status is “green” and the number of nodes in the cluster has been reduced by one.

Conclusion

In conclusion, removing a node from an Elasticsearch cluster involves disabling shard allocation, optionally performing a synced flush, excluding the node from the cluster, and stopping the Elasticsearch process on the node. By following these steps, you can safely remove a node without impacting the cluster’s performance or causing data loss.

How helpful was this guide?

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?