Want to get Elastic certified? Find out when the next Elasticsearch Engineer training is running!
Elasticsearch is packed with new features to help you build the best search solutions for your use case. Dive into our sample notebooks to learn more, start a free cloud trial, or try Elastic on your local machine now.
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
1. Stop indexing and perform a synced flush (optional)
First, if you can afford to stop indexing for a short period, it is recommended to perform a synced flush. This operation helps speed up the recovery process when the cluster restarts after a node is removed. To perform a synced flush, execute the following command:
Note that this step is optional and can be skipped if stopping indexing is not feasible.
2. Retrieve the node name
After performing a sync flush, you will need to know the node name in order to remove it from the cluster. You can retrieve the node name by executing the following command:
This command will return a list of nodes in the cluster along with their node names. Identify the node you want to remove and note down its node name.
3. Remove the node from the cluster
After you’ve determined the node name, you can remove the node from the cluster. To remove the node from the cluster, update the cluster settings to exclude the node using its node name. Execute the following command, replacing `<node_name>` with the node name you retrieved in the previous step:
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:
Wait for the shard relocation process to complete before proceeding to the next step.
4. Stop the Elasticsearch process on the node
After all shards have relocated to the other nodes, 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:
5. Verify the cluster health
Finally, verify the health of the cluster by executing the following command:
Ensure that the cluster status is “green” (meaning that all shards are properly allocated) and the number of nodes in the cluster has been reduced by one.
Elastic Cloud Serverless
Another option to avoid worrying about nodes is using Elastic Cloud Serverless. In this fully managed solution, Elastic takes care of the underlying architecture of your cluster, meaning you don’t need to worry about nodes, shards, or scaling, everything happens automagically.
Conclusion
In conclusion, removing a node from an Elasticsearch cluster involves disabling shard allocation to that node, 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. If you are looking for a managed solution, you could use Elastic Cloud Serverless.