Keeping Search Alive on a Legacy Platform With No Budget
Every search tutorial starts the same way: create an index, define a mapping, index some documents, run a query. Nobody inherits search like that. You inherit a cluster that four teams have touched over six years. It powers a marketplace or a gaming hub with millions of listings, and nobody fully understands it. You get no extra headcount, and the instruction is "just make it better".
This is the playbook I wish I had the first time. It assumes Elasticsearch or OpenSearch, but most of it applies to any search engine bolted onto a big product.
Week one: find out what you actually have
Do not change anything yet. Map it first. Most search incidents I have seen came from someone "cleaning up" an index that another service was still reading.
| Question | Where to look |
|---|---|
| Which indices exist and how big are they? | GET _cat/indices?v&s=store.size:desc |
| Who writes to each index? | Grep the codebase for index names; check ingest pipelines and cron jobs |
| Who reads from it? | Slow log, proxy logs, client user agents |
| Are there aliases, and do clients use them? | GET _cat/aliases?v |
| How many fields does each mapping have? | GET index/_mapping; count leaf fields |
| What are the slowest queries? | Enable the search slow log at a sensible threshold |
| How far behind the database is the index? | Compare updated_at of recent rows with indexed documents |
Write the answers down in one page. That page becomes the most valuable document your team owns.
The usual problems in an old cluster
Almost every inherited search setup has some of these:
- Mapping explosion. Dynamic mapping was left on, someone indexed user-supplied attributes as fields, and now the index has 9,000 fields. Every new field costs cluster-state memory. Fix it with
"dynamic": "strict"(orfalse) on new indices and a flattened or key-value structure for arbitrary attributes. - Clients hard-coded to physical index names. You cannot reindex without a coordinated deploy. Fix it with an alias, even if it is the only change you make this quarter.
- Shards sized at random. Hundreds of tiny shards waste heap; a few 200 GB shards make recovery painful. A common guideline is roughly 10 to 50 GB per shard.
- Deep pagination. Clients page with
fromandsizeuntil they hitindex.max_result_window(10,000 by default), and someone has raised it to a million to "fix" it. Usesearch_afterwith a point in time for deep scrolling, and cap UI pages. - Sync drift. The application writes to the database and then to the index in the same request. If the second write fails, the two disagree forever. Use an outbox table or change data capture (Debezium on the database log) so the index can always be rebuilt from the source of truth.
- Relevance by superstition. Boosts like
title^7that nobody can explain, and synonyms added during an incident in 2019.
Stop the bleeding before you improve anything
With limited resources, safety work beats feature work:
- Put every client behind an alias.
listingspoints tolistings_v12. Clients never see version numbers again. - Turn on the slow log and a basic dashboard. Watch p95 latency, error rate, indexing lag and heap.
- Snapshot to object storage on a schedule. Restoring a snapshot is your undo button.
- Freeze the mapping. New indices get strict mappings; unknown fields go to a flattened field.
- Write a rebuild job. One command that builds a fresh index from the database. If you cannot rebuild the index, you do not own it.
Reindexing a live index without downtime
This is the move you will make over and over:
# 1. Create the new index with the corrected mapping and no replicas
PUT listings_v13 { "settings": { "number_of_replicas": 0, "refresh_interval": "-1" }, "mappings": { ... } }
# 2. Copy the data (or rebuild from the database with your rebuild job)
POST _reindex?wait_for_completion=false
{ "source": { "index": "listings_v12" }, "dest": { "index": "listings_v13" } }
# 3. Restore replicas and refresh, then swap the alias atomically
PUT listings_v13/_settings { "number_of_replicas": 1, "refresh_interval": "1s" }
POST _aliases
{ "actions": [
{ "remove": { "index": "listings_v12", "alias": "listings" } },
{ "add": { "index": "listings_v13", "alias": "listings" } } ] }
The catch is writes that land during the copy. Either dual-write to both indices while you reindex, or record the reindex start time and replay everything changed since then from the outbox. Keep the old index for a few days, so a bad swap is just another alias change.
Fix relevance with data, not opinions
You cannot afford a relevance team, but you can afford a spreadsheet:
- Export the top 200 queries from the logs, plus 100 random ones from the long tail.
- For each one, note the result users actually clicked or bought.
- Turn that into a judgment set and run it through the
_rank_evalAPI, measuring precision or nDCG at 10. - Change one thing at a time: a boost, a synonym, a field. Keep it only if the score goes up.
The two biggest wins I usually find are not clever. Zero-result queries show what is missing: typos, plurals, synonyms, categories with a different name. Filters done as queries are the other: move exact matches (category, region, in stock) into filter clauses, which are cached and do not affect scoring.
When you finally get some budget
Spend it in this order. First, a proper ingestion pipeline (outbox or change data capture) so the index never drifts. Second, a nightly relevance check against your judgment set, so nobody silently breaks ranking. Only then look at fancy things like semantic or vector search. A hybrid of BM25 and embeddings can be great, but on a platform where the basic index is wrong half the time, it only makes the wrong results look smarter.
Legacy search is not glamorous. Most of the job is aliases, snapshots, logs and patience. But it is one of the few places where a single engineer can move a big platform's revenue, because when search gets better, people find what they came to buy.