Skip to content

Widhian Bramantya

coding is an art form

Menu
  • About Me
Menu
elasticsearch

Blue-Green Deployment in Elasticsearch: Safe Reindexing and Zero-Downtime Upgrades

Posted on October 5, 2025October 5, 2025 by admin

Reindexing or upgrading Elasticsearch can be risky when your system is already in production.
If you change mappings, update analyzers, or move to a new version, stopping the cluster is not an option.
That’s where the blue-green strategy helps, it allows you to build a new index (or cluster), test it, and switch traffic smoothly without downtime.

What Is Blue-Green Deployment?

In a blue-green setup, you have two environments:

EnvironmentPurpose
BlueThe current (live) index or cluster that handles all user queries
GreenThe new index or cluster that receives fresh data and testing

Once the green environment is ready and validated, you simply switch an alias or connection, users instantly move from blue to green. If something goes wrong, you can roll back to blue within seconds.

When Do You Need It?

Blue-green deployment is useful when you must:

  • Change mappings or analyzers (e.g., modify a field type from text to keyword)
  • Add new fields that require reindexing
  • Upgrade Elasticsearch to a new major version (for example, from 7.x → 8.x)
  • Clean up corrupted data or fix index settings
  • Move to new hardware or cloud nodes

Blue-Green Reindex Strategy (Same Cluster)

This is the simplest case — both blue and green indices exist inside the same cluster.

Step 1 Create the New Index (Green)

Design your new mapping carefully.

PUT my_index_v2
{
  "settings": {
    "number_of_shards": 5,
    "number_of_replicas": 1
  },
  "mappings": {
    "properties": {
      "title": { "type": "text", "analyzer": "english" },
      "price": { "type": "float" }
    }
  }
}

Step 2 Reindex Data from the Old Index

Copy all documents from the blue index to the new one.

POST _reindex
{
  "source": { "index": "my_index_v1" },
  "dest": { "index": "my_index_v2" },
  "conflicts": "proceed"
}

For large datasets, run it in the background:

POST _reindex?wait_for_completion=false

and track progress:

GET _tasks?detailed=true&actions=*reindex

Step 3 Test the New Index

Compare document counts:

GET my_index_v1/_count
GET my_index_v2/_count

Try a few search queries and aggregations to confirm the same results.
You can also benchmark query latency or relevance scoring.

See also  Basic Concept of ElasticSearch (Part 3): Translog, Flush, and Refresh

Step 4 Switch Aliases

Use aliases to change which index your application points to.

POST /_aliases
{
  "actions": [
    { "remove": { "index": "my_index_v1", "alias": "my_index" } },
    { "add":    { "index": "my_index_v2", "alias": "my_index" } }
  ]
}

All apps that query my_index will now automatically read from the new index — zero downtime.

Step 5 Clean Up or Archive

When you are sure the new version works:

DELETE my_index_v1

Or snapshot it for backup before deletion.

Handling Continuous Writes

If your system is still receiving new data while reindexing, you have two options:

Option A Dual Write

Write to both indices (v1 and v2) until the switch is done.
After switching, stop writing to v1.

Option B Catch-Up Reindex

Pause writes for a short time (maintenance window), reindex only the delta:

POST _reindex
{
  "source": {
    "index": "my_index_v1",
    "query": {
      "range": { "@timestamp": { "gte": "2025-10-05T00:00:00Z" } }
    }
  },
  "dest": { "index": "my_index_v2" }
}

Then switch aliases.

Pages: 1 2 3
Category: ElasticSearch

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Linkedin

Widhian Bramantya

Recent Posts

  • Log Management at Scale: Integrating Elasticsearch with Beats, Logstash, and Kibana
  • Index Lifecycle Management (ILM) in Elasticsearch: Automatic Data Control Made Simple
  • Blue-Green Deployment in Elasticsearch: Safe Reindexing and Zero-Downtime Upgrades
  • Maintaining Super Large Datasets in Elasticsearch
  • Elasticsearch Best Practices for Beginners
  • Implementing the Outbox Pattern with Debezium
  • Production-Grade Debezium Connector with Kafka (Postgres Outbox Example – E-Commerce Orders)
  • Connecting Debezium with Kafka for Real-Time Streaming
  • Debezium Architecture – How It Works and Core Components
  • What is Debezium? – An Introduction to Change Data Capture
  • Offset Management and Consumer Groups in Kafka
  • Partitions, Replication, and Fault Tolerance in Kafka
  • Delivery Semantics in Kafka: At Most Once, At Least Once, Exactly Once
  • Producers and Consumers: How Data Flows in Kafka
  • Kafka Architecture Explained: Brokers, Topics, Partitions, and Offsets
  • Getting Started with Apache Kafka: Core Concepts and Use Cases
  • Security Best Practices for RabbitMQ in Production
  • Understanding RabbitMQ Virtual Hosts (vhosts) and Their Uses
  • RabbitMQ Performance Tuning: Optimizing Throughput and Latency
  • High Availability in RabbitMQ: Clustering and Mirrored Queues Explained

Recent Comments

  1. Playing with VPC AWS (Part 2) – Widhian's Blog on Playing with VPC AWS (Part 1): VPC, Subnet, Internet Gateway, Route Table, NAT, and Security Group
  2. Basic Concept of ElasticSearch (Part 3): Translog, Flush, and Refresh – Widhian's Blog on Basic Concept of ElasticSearch (Part 1): Introduction
  3. Basic Concept of ElasticSearch (Part 2): Architectural Perspective – Widhian's Blog on Basic Concept of ElasticSearch (Part 3): Translog, Flush, and Refresh
  4. Basic Concept of ElasticSearch (Part 3): Translog, Flush, and Refresh – Widhian's Blog on Basic Concept of ElasticSearch (Part 2): Architectural Perspective
  5. Basic Concept of ElasticSearch (Part 1): Introduction – Widhian's Blog on Basic Concept of ElasticSearch (Part 2): Architectural Perspective

Archives

  • October 2025
  • September 2025
  • August 2025
  • November 2021
  • October 2021
  • August 2021
  • July 2021
  • June 2021
  • March 2021
  • January 2021

Categories

  • Debezium
  • Devops
  • ElasticSearch
  • Golang
  • Kafka
  • Lua
  • NATS
  • Programming
  • RabbitMQ
  • Redis
  • VPC
© 2025 Widhian Bramantya | Powered by Minimalist Blog WordPress Theme