Cross-cluster replication only replicates forward in version, and an 8.x cluster only follows 7.17 or later. For a major upgrade and a platform move in one run, with a way back, I wrote a sync that works at the REST layer.

This is the last part of the series, and the one I'm proudest of, because it is the problem CCR couldn't solve for us.

The problem

We needed to upgrade from 7.x to 8.x and move to a new environment in the same project. CCR's rules ruled it out:

  • Followers must be the same version or newer, down to the patch level. An 8.x follower can only follow a 7.17 or later leader.
  • Nothing replicates from 8.x back to 7.x. After cutover there is no replication stream back to the old cluster, so no rollback path.
  • Two-way CCR pauses during upgrades. Because each cluster follows the other, a bi-directional pair has to pause replication, upgrade both sides and resume. One-way CCR upgrades the follower first, then the leader. Either way, there is no two-way coverage during the window.
  • CCR needs a transport-layer path between the old datacenter and the new environment, plus a subscription on both sides.

The decision: replicate at the REST layer

Every Elasticsearch version speaks JSON over HTTP. A sync that only searches the source and bulk-indexes into the target doesn't care about versions, platforms, the transport layer, or direction. So I built one. The code stays private; the design below is the useful part.

What the tool does

  1. One-time backfill. Scroll each index that matches a pattern and bulk-index into the target with the same _id. Because ids are preserved, a rerun overwrites instead of duplicating, so every run is idempotent. When the target rejects a request as too large (HTTP 413), the tool halves the batch and retries. Failed documents are logged per index.
  2. Incremental catch-up. The watermark for each index is the maximum value of the application's last-updated field already present in the target. It is read from the target at the start of every run, so the tool keeps no external state and recovers on its own after a crash.
  3. Time windows. From the watermark, copy fixed windows forward: a day at a time early on, shorter windows near cutover. Skip ahead when the source has nothing newer, and stop at the present.
  4. An audit trail in both clusters. For every window, write one record to a copy-log index on both the source and the target: index, window, document count, status, any error, and both cluster names. Progress is queryable from either side and survives the cutover.
  5. Scope to active periods. Process only indices whose names fall in the active months, so a run doesn't rescan years of history.
  6. Safe under cron. A wrapper takes a lock file with a PID check, clears stale locks, and writes a dated log per day.
  7. A verifier. A separate pass pulls (id, last-updated) pairs from both clusters and lists documents that are missing or stale on the target.

A sync job reads a watermark from the target, copies time windows from the source, and logs progress in both clusters.

Upgrade and migration in the same run

  1. Build the new 8.x cluster on the new platform. Pre-create templates, mappings, ILM policies and roles under the new version's rules. 8.x has no mapping types, and because the tool sends only _source, old type metadata falls away naturally. Data-tier roles replace attribute-based allocation.
  2. Backfill.
  3. Run the incremental loop until the lag is a few minutes.
  4. Freeze writers, run a final pass, and get a clean verifier report.
  5. Cut the applications over.
  6. Flip the direction: sync new to old during a safety window. That is the rollback path CCR can't give you.
  7. Decommission the old cluster.

Set ILM origination dates on backfilled history, or old months will look new to ILM (Part 5).

Limits, honestly

  • Hard deletes are invisible to a watermark. Use a soft-delete flag or tombstones, or rely on the verifier to catch them.
  • It depends on a trustworthy last-updated field that the application sets on every write. Clock skew and late writes call for overlapping windows; because ids are preserved, re-copying the overlap is safe.
  • It is slower than CCR's file-level copy. It is built for catch-up, not continuous low-latency replication.
  • On newer versions, prefer point-in-time with search_after over scroll for large reads.
  • Keep TLS verification on and credentials in a secrets store, not in a config file beside the script. That one is a lesson from the early versions.

Choosing an approach

Approach Recovery point DR readable? Crosses versions? Ops cost Best for
Snapshot and restore (SLM) Hours Not during restores Forward one major Low to medium Backups, cold DR
CCR, one-way Near real time Yes, read-only Follower same or newer Medium Warm DR, read offload
CCR, two streams Near real time Yes In practice, same version High Two active sites, append-mostly data
REST-level sync Minutes (window size) Yes Any direction Medium; you own the code Upgrades, migrations, rollback
Dual write or Kafka fan-out Depends on the pipeline Yes Yes High (consistency) Source of truth upstream, replayable
Cross-cluster search No copy Queries go remote Within compatibility rules Low Global reads without copying
OpenSearch cross-cluster replication Near real time Yes, read-only Within its own rules Medium Teams already on OpenSearch

Series wrap-up

Nothing in this series is exotic. Every piece is a documented feature. The work was in the seams: index names that encode ownership, metadata that doesn't travel, versions that only move forward, and monitoring that tells you when replication has quietly stopped. If you take three habits away, take these: write a heartbeat and alert on it, keep everything that isn't data in code applied to both clusters, and plan your way back before you need it.

Risks and precautions

  • A watermark sync misses hard deletes unless you design for them.
  • Your rollback window is only as good as the reverse sync running during it. Test the flip before cutover day.
  • Pre-create templates and mappings on the target. Letting the target guess mappings from the first documents is how fields end up with the wrong type.
  • Keep the verifier report as your cutover sign-off.
  • Own the code: a home-grown sync needs tests, logs and an owner, just like any production service.

Eight numbered tiles marking the completed series, with the words Plan the way back before you need it.

Part 8 of 8 in Elasticsearch Replication & DR Field Notes. Previous: Part 7, Failover, Failback, and the 2,000-Index Unfollow Problem. Start of series: Part 1, Elasticsearch DR the Hard Way.

Sources