~learn.
0:00 / 1:22
W07 · Search system

Rebuild the whole search index, and nobody notices

transcript

You need to rebuild your entire search index. And search can't go down. Not for a second.

Say you change an analyzer, or a field's type. Why not just edit the mapping? The index already holds tokens from the old analyzer. You can't re-map them in place. You need a new index.

The trick: the app never talks to a real index. It talks to an alias. Products. The alias points at v1. Reads stay there, on a complete index. Meanwhile, the pipeline writes every update to both v1 and the new v2.

Copy the old data into v2. Here's the subtle bit: op type create. It never overwrites a newer document the pipeline already wrote. Compare counts. More than 0.1 percent apart? Roll back. Then swap the alias in one atomic call. Wait 30 seconds, and delete v1.

Before the swap, searches hit a complete v1. After it, a complete v2. Read v2 early, and users would see a half-copied index. They never do.

The app never learns the real index name. That's the point. Use aliases from day one. Because you will reindex.

Full breakdown in the lecture.