Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Rolling Upgrades in Elasticsearch

Introduction

Rolling upgrades allow you to upgrade your Elasticsearch cluster to a new version without any downtime. This is crucial for maintaining the availability and reliability of your search services. This tutorial will guide you through the process of performing a rolling upgrade on your Elasticsearch cluster.

Prerequisites

Before performing a rolling upgrade, ensure the following prerequisites are met:

  • All nodes in the cluster are running a version that supports rolling upgrades.
  • You have a full backup of your data.
  • Your cluster is in a healthy state (green).

Step 1: Check Cluster Health

First, check the health of your cluster to ensure it is in a green state:

GET /_cluster/health
{ "cluster_name": "elasticsearch", "status": "green", "timed_out": false, "number_of_nodes": 3, "number_of_data_nodes": 3, "active_primary_shards": 10, "active_shards": 20, "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 0, "delayed_unassigned_shards": 0, "number_of_pending_tasks": 0, "number_of_in_flight_fetch": 0, "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 100.0 }

Ensure the status is green. If the status is not green, resolve any issues before proceeding.

Step 2: Disable Shard Allocation

To prevent Elasticsearch from rebalancing shards during the upgrade, disable shard allocation:

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

Step 3: Upgrade Nodes One by One

Upgrade each node in the cluster one at a time. Follow these steps for each node:

  1. Shut down the node:
  2. systemctl stop elasticsearch
  3. Install the new version of Elasticsearch:
  4. apt-get update && apt-get install elasticsearch
  5. Start the node:
  6. systemctl start elasticsearch
  7. Wait for the node to rejoin the cluster and become healthy.

Step 4: Re-enable Shard Allocation

Once all nodes are upgraded, re-enable shard allocation:

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

Step 5: Verify Cluster Health

Check the cluster health again to ensure it is in a green state:

GET /_cluster/health
{ "cluster_name": "elasticsearch", "status": "green", "timed_out": false, "number_of_nodes": 3, "number_of_data_nodes": 3, "active_primary_shards": 10, "active_shards": 20, "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 0, "delayed_unassigned_shards": 0, "number_of_pending_tasks": 0, "number_of_in_flight_fetch": 0, "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 100.0 }

Conclusion

Congratulations! You have successfully performed a rolling upgrade on your Elasticsearch cluster. This process ensures that your cluster remains available and operational throughout the upgrade.