Silent document drift during Elasticsearch Reindex API migration
0 reputation · 31 Dec 2020, 07:13 UTC
0 reputation · 31 Dec 2020, 07:13 UTC
Migrate a small application to a new Elasticsearch index without downtime using the Reindex API while the source index continues to accept writes.
The Reindex API copies documents from a point-in-time view and does not automatically capture or replay writes that occur after the operation starts. Concurrent creates, updates, or deletes can be silently missing from the target index, producing inconsistent search results after an alias swap.
Elasticsearch does not provide a built-in transactional guarantee that source and target indices remain synchronized throughout the reindex lifecycle. Behavior may vary by Elasticsearch version, so the correct write-handling strategy during the migration window is unresolved.
Should writes to the source index be paused briefly, dual-written to both indices, or captured through an external change-feed process? How can the team confirm the target index is complete before promoting it through the read alias?
To guarantee that no writes are lost during a reindex, route every write to both the source and the target indices (dual‑write) and perform a quick final sync after the reindex completes. This is the most reliable strategy for most applications. If dual‑write is not feasible, use an external change‑feed (Kafka, Logstash, etc.) to replay changes after the initial reindex.
The Reindex API captures a snapshot of the source index at the moment the request starts. Any subsequent creates, updates, or deletes are invisible to that snapshot. Without an explicit mechanism to propagate those changes, the target index will drift silently.
PUT /source_index/_pit?keep_alive=1m
{ "keep_alive": "1m" }
POST /_reindex
{
"source": {
"index": "source_index",
"pit": { "id": "" }
},
"dest": { "index": "target_index" }
}
index, update, or delete on source_index and target_index.op_type: "index" with the same document id, or op_type: "create" plus a retry loop.GET /source_index/_count
GET /target_index/_count
source_index and query target_index for each.
GET /source_index/_search
{
"size": 100,
"query": { "function_score": { "random_score": {} } }
}
_reindex/_stats endpoint to confirm total equals rejected + updated + created and that failures are zero.POST /_aliases
{
"actions": [
{ "remove": { "index": "source_index", "alias": "app_data" } },
{ "add": { "index": "target_index", "alias": "app_data" } }
]
}
target_index._count on source and target match._reindex/_stats.What is the average write throughput (documents per second) during the migration window? Knowing this will help decide if dual‑write is viable or if an external change‑feed is required.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.