Scrivio Interview library
ScenarioAdvanced6 min read · updated 12 November 2026

Product search over 200 million documents has slow queries and indexing takes 70 percent of cluster CPU. Many fields are indexed that nobody searches. How would you reduce index cost without hurting search?

I would first audit the real queries to learn which fields are searched, filtered, sorted or aggregated, then slim the mapping: index: false for fields only displayed, doc_values: false for fields never sorted or aggregated, no duplicate indexing of large text, and explicit mappings with dynamic: strict to stop field explosion. Large raw payloads move to another store, and the new mapping goes into a fresh index built with reindexing behind an alias, so we can compare latency and relevance before switching.

Why this question is asked

Search clusters tend to grow by accumulation. Each team adds a few fields, dynamic mapping indexes every one of them in several ways, and after a few years most of the indexing work serves fields that nobody queries. At 200 million documents that waste is the difference between a calm cluster and one that spends 70 percent of its CPU indexing. Interviewers ask this scenario to see whether we know what each mapping option costs and how to change mappings safely. In this answer, we will see where indexing cost comes from, audit the queries, slim the mapping field by field, move payloads out, and roll out the new index without harming search.

1Where the Indexing Cost Comes From

For each field in a document, Elasticsearch or OpenSearch can build several structures. A text field is analysed into terms and added to an inverted index, often with positions for phrase queries and norms for scoring. A keyword field gets an inverted index for exact matching and, by default, doc values, a column-oriented copy used for sorting and aggregations. Numbers and dates get BKD trees for range queries plus doc values. And the whole original JSON is stored in _source.

Dynamic mapping adds to this. A new string field is mapped as text with a keyword subfield, so it is analysed and also indexed as a keyword with doc values. A product document with 150 fields can easily produce 300 indexed structures. Every one must be built on each write, merged in the background and kept in memory or disk caches. So the cheapest structure is the one we do not build.

2Auditing How Fields Are Really Used

Before changing anything, we need evidence. Good sources are the application's query builders, the slow log and any query logging, saved dashboards that run aggregations, and the field usage statistics API, which reports per-field usage on the shards (check your version and distribution for it). The result is a classification of every field.

Field audit for the product index
FieldUsed forMapping decision
title, descriptionfull-text searchtext, keep
brandfilter, aggregationkeyword, keep doc_values
skuexact search onlykeyword, doc_values: false
pricefilter, sortscaled_float or double, keep
image_urls, marketing_htmldisplay onlyindex: false or not in index
supplier_payload (40 KB JSON)never queriedmove to another store
120 vendor attributesrarely, unknownflattened field or not indexed
Only a handful of fields need full indexing; most only need to be returned.

3Slimming the Mapping Field by Field

With the audit done, each field gets only the structures its usage needs. We write the mapping explicitly and set dynamic to strict, so a document with an unknown field is rejected instead of silently adding new indexed fields.

YAML
PUT /products_v2
{
"mappings": {
"dynamic": "strict",
"properties": {
"title": { "type": "text", "fields": { "raw": { "type": "keyword" } } },
"description": { "type": "text", "index_options": "freqs" },
"brand": { "type": "keyword" },
"sku": { "type": "keyword", "doc_values": false },
"price": { "type": "scaled_float", "scaling_factor": 100 },
"image_urls": { "type": "keyword", "index": false, "doc_values": false },
"attributes": { "type": "flattened" }
}
}
}

Each line has a reason. image_urls is only returned, so it is neither indexed nor given doc values; it stays in _source. sku is matched exactly but never sorted, so doc_values is off. description drops positions with index_options: freqs, which saves a lot on long text, but only if nobody runs phrase queries on it, which the audit must confirm. We keep a keyword subfield on title only because the audit showed sorting by title. And the vendor attributes go into one flattened field (flat_object in OpenSearch) instead of 120 separate fields. Avoiding duplicate indexing of large text matters most: copy_to into an all-fields field, plus separate analyzers on the same description, can double the cost of the biggest fields.

4Moving Large Payloads Out of the Index

The 40 KB supplier payload never takes part in search but is stored in _source on every document, written to the translog, compressed, merged and copied to replicas. At 200 million documents that is around 8 TB before compression. The better home is the database or object store that is already the source of truth. The index keeps the product id, and the application fetches the payload by id when a detail page needs it.

We should be careful with the opposite shortcut of disabling _source entirely. It saves space but breaks reindexing, update APIs and many debugging tools, so excluding specific large fields, or moving them out, is safer than turning _source off.

5Rolling Out the New Index Behind an Alias

Mapping changes like these cannot be applied to the existing index, so we build products_v2 next to products_v1. The application already reads and writes through an alias, products, which points at v1.

Java
POST /_reindex?slices=auto&wait_for_completion=false
{ "source": { "index": "products_v1" }, "dest": { "index": "products_v2" } }
// returns a task id; GET /_tasks/<id> shows progress
// compare: counts, a set of real queries, latency, relevance judgments
GET /products_v1/_count // 200,000,000
GET /products_v2/_count // 200,000,000
POST /_aliases
{ "actions": [
{ "remove": { "index": "products_v1", "alias": "products" } },
{ "add": { "index": "products_v2", "alias": "products", "is_write_index": true } } ] }

Before the switch we replay a sample of production queries against both indices and compare latency and the top results, ideally against a judged query set, so we know relevance did not change by accident. Changes made during the reindex are caught up by dual writing or by re-running the indexer for documents updated since the start. After the switch, indexing CPU should drop sharply; in cases like this one a reduction by half or more is common, because most of the structures being built are gone. We keep v1 for a few days for rollback.

6Follow-up questions

Is it enough to set index: false on the existing index?

No. Most mapping parameters of existing fields cannot be changed in place. A new index with the new mapping and a reindex is the normal path.

What does doc_values: false save, and what does it break?

It saves the column-oriented copy of the field on disk and the work to build it. Sorting, aggregations and scripts on that field stop working, so we only disable it on fields the audit shows are never used that way.

Could we reduce replicas instead?

Fewer replicas reduce indexing work but also reduce search capacity and resilience. Slimming the mapping removes waste; cutting replicas removes safety. Do the first before considering the second.

7Conclusion

In this answer, we traced indexing cost to the structures built per field: inverted indexes, positions, norms, doc values and _source. We audited real usage, kept full indexing only for fields that are searched, filtered, sorted or aggregated, used index: false, doc_values: false, slimmer index_options and a flattened field for the rest, set dynamic: strict, moved the large payload to its own store, and rolled out the new mapping through a reindex behind an alias with a comparison of latency and relevance.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start with evidence: audit which fields are actually searched, filtered, sorted or aggregated, from the query builders, slow logs, dashboards and the field usage stats where available.

Then, if they want more

Usually only a small set is. Then I would design a slimmer explicit mapping. Fields that are only displayed get index false and doc_values false, and stay in _source. Fields matched exactly but never sorted or aggregated keep the index but drop doc values. Long text that never needs phrase queries can drop positions.

I would remove duplicate indexing of big text, like copy_to all-fields or several analyzers on the same description, and put arbitrary vendor attributes into one flattened field instead of hundreds. I would set dynamic to strict so new fields cannot explode the mapping again.

Large raw payloads that nobody searches, like a 40 KB supplier JSON, move to the source database or object storage, and the app fetches them by id. Since these changes cannot be applied in place, I would create a new index, reindex with slices, catch up changes made in the meantime, and keep the application on an alias.

Before swapping the alias atomically, I would replay real queries and compare latency and relevance on a judged set, then swap, watch indexing CPU drop, and keep the old index briefly for rollback.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Elasticsearch documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Product search over 200 million documents has slow queries and indexing takes 70 percent...": https://scrivio-interview-library.netlify.app/databases/search-engines/43c3e434c6/