Scrivio Interview library

Elasticsearch, OpenSearch and Lucene

24 questions in 7 subtopics.

Inverted index

ConceptFoundations6 min read
What is an inverted index, and why does it make full-text search fast compared with LIKE '%term%' in a relational database?
InternalsIntermediate6 min read
How do Elasticsearch and OpenSearch make newly indexed documents searchable, and what do refresh, flush and the translog do? Why does a document written with a 200 OK not appear in search immediately?
ScenarioAdvanced6 min read
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?

Analyzers and tokenization

ConceptFoundations5 min read
What does an analyzer do in Elasticsearch? Describe character filters, tokenizers and token filters, and what the standard analyzer produces for 'The Quick-Brown Foxes!'.
DebuggingIntermediate6 min read
Searching for product code 'AB-1234' returns many unrelated products, and an exact match is not first. The field is mapped as text with the standard analyzer. Explain the cause and fix.
DesignAdvanced6 min read
Your marketplace operates in 12 languages, including Japanese and German. How would you design analysis and indexes for multilingual search, and what trade-offs come with each option?
LeadershipPrincipal5 min read
Search quality complaints reach your desk from many product lines, and each team tunes analyzers and synonyms on its own. How would you organise search relevance as a capability across the company?

Relevance scoring and BM25

ConceptFoundations6 min read
Explain how BM25 scores a document for a query. What do term frequency, inverse document frequency and field length normalisation contribute?
DebuggingIntermediate5 min read
In a test environment with 3 shards and 20 documents, search ranking is inconsistent between runs and differs from production. What causes this and how do you deal with it?
ScenarioAdvanced6 min read
Business wants search results ranked by relevance but also boosted by popularity, stock availability and margin. How would you design the ranking and keep it explainable?

Mappings

ConceptFoundations5 min read
What is the difference between text and keyword fields in Elasticsearch mappings, and why do teams often map a string field as both?
CodingIntermediate7 min read
You must change a field from text to keyword in an existing index with 50 million documents and no downtime for search. Describe the steps and the APIs you would use.
ScenarioIntermediate7 min read
A logging index has over 10,000 fields because services send arbitrary JSON keys, and the cluster rejects writes with 'Limit of total fields [1000] has been exceeded'. How do you fix it properly?

Keeping search in sync with the database

ScenarioFoundations7 min read
A Spring Boot service saves a product to PostgreSQL and then calls Elasticsearch to index it in the same method. Sometimes search shows stale or missing products. Why, and what simple improvements would you make?
DesignIntermediate7 min read
Design reliable synchronisation of 30 million rows from PostgreSQL into OpenSearch, including the initial load and ongoing changes, with eventual consistency within 5 seconds.
ScenarioAdvanced7 min read
The search index must denormalise data from four services (product, price, stock, reviews). Updates arrive out of order and some documents show prices from yesterday. How do you design the pipeline?
LeadershipPrincipal7 min read
Several teams run their own search clusters with homegrown sync jobs, and incidents of stale search keep recurring. Should the company build a central search platform, buy a managed service, or let teams continue? How do you decide?

Lucene basics

ConceptFoundations7 min read
What are Lucene segments, and why are deletes and updates not applied in place?
CodingIntermediate7 min read
Using the Lucene Java API directly, outline the code to index documents with a title and an id and then search for a term. Which classes are involved, and when would you embed Lucene instead of running Elasticsearch?
InternalsAdvanced7 min read
Explain how doc values, stored fields and the inverted index differ inside Lucene, and how that explains Elasticsearch memory and disk sizing.

Shards and replicas in search clusters

ConceptFoundations7 min read
What are primary shards and replicas in Elasticsearch or OpenSearch, and why can you not easily change the number of primary shards of an existing index?
ScenarioIntermediate6 min read
A cluster has 40,000 small shards across 12 nodes from daily indices with 5 shards each, and the master is slow and heap usage is high. What is wrong and how do you fix it?
DesignAdvanced6 min read
Design a multi-tenant search service for 5,000 customers, where 20 large tenants hold 70 percent of the data. Would you use an index per tenant, a shared index with routing, or a hybrid?
DesignPrincipal6 min read
Your search clusters have grown to petabytes over a decade, mostly logs, and cost is rising faster than revenue. What long-term architecture and policy decisions would you make?