
Index Synchronization: Keeping Search in Step with Data
A search index is a derived copy, and derived copies of changing data drift. Here are the two update paths, idempotent upserts, the build-alongside reindex, and per-field freshness contracts.
TL;DR: A search index is a derived copy of your source of truth, and a derived copy of changing data drifts unless the pipeline is designed against it — the deleted product still ranking on page one is the natural state of an unmanaged copy, not a glitch. What keeps it in step is idempotent full-document upserts, incremental updates backed by a periodic rebuild, a build-alongside-and-swap reindex, and freshness contracts written per field rather than per system.
Two systems, one truth
The index is not the database. It is a transformed, denormalized, analyzer-processed copy of selected parts of the database, optimized for a completely different access pattern. That is what makes it fast, and it is also what makes drift the default: two stores holding overlapping facts that keep changing will diverge unless something continuously reconciles them.
Drift reaches users in three distinct shapes, and it is worth naming them separately because they have different causes and different costs.
Stale results are documents that changed in the source and have not been reindexed. The price shown in search is an outdated price. The article's title was rewritten and search still shows the old one. Annoying, usually survivable.
Ghost results are documents deleted in the source and still present in the index. The user searches, sees the item, clicks it, and lands on a missing page. This is especially trust-corrosive, and the reason is worth being precise about: the site's own search sent the user to something that does not exist. A missing item a user never saw costs nothing; an item search advertised and then failed to produce costs the user's confidence in search itself.
Missing results are documents created in the source and never indexed. They are invisible by definition, which makes them hard to notice and easy to under-count — nobody reports a search result they do not know should exist.
Deletes are an easy hole to leave in the pipeline, and the reason is structural rather than careless. Create and update flows get built because their absence is loud: a new product does not appear, someone files a ticket that afternoon. Delete propagation is easy to skip because its absence looks like nothing at all — the pipeline reports success, the index is happily serving a document, and nothing in the system knows anything is wrong until the ghost complaints arrive much later.
What flows through this pipeline — the document shape, its fields, its enrichment, its analyzer bindings — is the index's document design. This is about movement, not shape.
The two update paths and their failure modes
Batch reindex rebuilds the index from the source on a schedule. It is simple, it is self-healing — every run erases whatever drift accumulated since the last one — and it is stale by construction in between. For a small corpus of slow-changing content, batch reindex as the sole mechanism is a correct engineering choice, and it should be stated without embarrassment. A documentation site whose pages change only occasionally does not need an event pipeline.
Event-driven incremental indexing consumes change events from the source and applies them as they arrive. It can be fresh within seconds and is fragile in three specific, nameable ways. Missed events: the indexer was down, or the queue dropped them, and the changes that happened during that window are simply not in the index — and nothing about the index's state says so. Out-of-order delivery: an update arrives after the delete that logically followed it, resurrecting a deleted document. Partial failures: five of six documents in a batch applied, the sixth failed, and whether that failure is retried, logged, or silently swallowed determines whether you have a temporary gap or a permanent one.
Idempotent upserts are the property that makes all three survivable. Write full documents keyed by the source identifier, with a version or timestamp guard so that an older version cannot overwrite a newer one. Then a replayed event is harmless, an out-of-order update is rejected by the guard rather than applied, and recovery from a missed window is a matter of replaying it rather than reasoning about what state the index is in. The guard has a time limit for deletes: in Elasticsearch, a deleted document's version number remains available for further versioned operations only for the index.gc_deletes period, which defaults to 60 seconds (Elasticsearch index settings reference, as of November 2026). An update that arrives after a delete and outside that period can therefore index the document again, and the periodic rebuild is what clears it. The alternative — delta patches that modify fields of an existing index document — is precisely how out-of-order delivery becomes silent corruption, because each patch assumes a base state and, unless it carries a concurrency check, does not verify it (Elasticsearch's update API, for example, accepts if_seq_no and if_primary_term so that the operation runs only if the document has that sequence number and primary term, as of November 2026). Upsert and version-guard semantics are documented directly in the dedicated-engine class (Elasticsearch index API reference, as of November 2026).
| Failure | Batch reindex | Event-driven incremental | Combined |
|---|---|---|---|
| Stale between updates | Always, by design | Seconds-scale lag | Seconds-scale lag |
| Missed change events | Not applicable | Permanent until next full rebuild | Corrected at next rebuild |
| Out-of-order delivery | Not applicable | Corruption without version guards | Rejected by guard while versions are retained, corrected at rebuild |
| Deleted document lingering | Cleared each run | Permanent if delete events are unhandled | Cleared at next rebuild |
| Cost profile | Full corpus pass per run | Per-change, small | Both, with the rebuild off-peak |
The combination in the last column deserves stating as the honest default rather than as a compromise: incremental updates for freshness, plus a periodic full rebuild as the self-healing backstop. Each covers the other's failure mode. The rebuild costs a scheduled corpus pass and buys the guarantee that no accumulated gap survives more than one cycle.
The zero-downtime reindex
A full rebuild is sometimes mandatory rather than scheduled. Changing an existing field's index-time analyzer or field type typically cannot be applied to an existing index, because the existing documents were processed with the old configuration and only reprocessing fixes them. Synonym sets applied at index time have the same property. And corrupted-index recovery is the case that is easy not to plan for. Adding a new field is different: Elasticsearch documents that new fields can be added to an existing index through the update mapping API, while, except for supported mapping parameters, the mapping or field type of an existing field can't be changed (Elasticsearch explicit mapping documentation, as of November 2026), and OpenSearch documents that you can add mappings to an existing index or data stream but cannot change the mapping of an existing field beyond modifying its mapping parameters (OpenSearch mappings documentation, as of November 2026).
The build-alongside pattern is the worked answer. Build the new index in full while the old one continues serving traffic. Validate it before it serves anything: document counts reconciled against the source, spot queries returning sensible results, and the golden query set run as an acceptance gate — this is the moment that set earns its maintenance cost, because it turns "the new index looks fine" into a comparison with evidence. Then switch atomically. In the engine classes that support aliases, the switch is repointing an alias from the old index to the new one, which is a metadata operation rather than a data migration (Elasticsearch aliases reference, as of November 2026); the same alias and reindex surfaces exist in the open-source engine class (OpenSearch index aliases documentation, as of November 2026). Verify against your engine's current documentation, since the mechanism name and its guarantees vary.
The double-write window is the detail that separates a clean swap from one that quietly loses an hour of updates. The rebuild takes time, and the source keeps changing during it. Those changes must either be written to both indexes as they arrive, or captured and replayed against the new index after the build completes but before the swap. Skipping this is a subtle bug: the swap succeeds, search works, and a specific window of changes is simply absent until the next rebuild.
Rollback is cheap if you plan it and expensive if you do not. Keep the previous index for a short retention period after the swap. A bad deploy then becomes an alias flip back — seconds — instead of an emergency rebuild under pressure with a degraded search serving live traffic.
Freshness contracts and drift monitoring
Freshness is a per-field property, not a per-system one, and conflating them can lead to trying to make everything real-time. Stock status and price can mislead users within minutes of going stale — someone buying an item that is no longer available experiences it as the site lying, and the recovery is a support conversation. A product description that is six hours out of date is far less likely to be noticed. A freshness contract names which fields carry which staleness budget, explicitly, instead of leaving the question unasked and defaulting to whatever the pipeline happens to deliver.
That contract then shapes the architecture. Volatile fields may deserve a fast lane — a separate, lighter update path that touches only those fields — or, where the field is critical enough and the engine permits it, a query-time lookup against the source rather than an indexed copy at all. Everything else rides the standard pipeline. This is a deliberate tiering decision, and it is far cheaper than trying to drive the whole corpus at the volatile fields' cadence.
Drift monitoring is what turns all of this from hope into verification. Three checks cover most of it: count reconciliation between source and index, so that a systematic gap shows up as a number rather than as a complaint; sampled document comparison on the volatile fields, which catches the fast lane silently failing while the standard pipeline keeps working; and indexing-lag measurement, the time between a source change and its appearance in the index, which is the metric that shows the pipeline falling behind. Alert on divergence, so the monitoring notices before the ghost-result complaints do.
Two boundaries. The event infrastructure itself — queue technology, delivery guarantees, retry and dead-letter policy — is general backend engineering with its own literature, and what belongs here is only what search requires of it: at-least-once delivery that idempotent upserts can tolerate, and a replay path. And the freshness discipline described here is inherited rather than reinvented by the suggest surface, whose entity suggestions must drop delisted items on the same cadence the index does.