Elasticsearch, OpenSearch and Lucene
24 questions in 7 subtopics.
Inverted index
What is an inverted index, and why does it make full-text search fast compared with LIKE '%term%' in a relational database?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?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
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!'.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.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?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
Explain how BM25 scores a document for a query. What do term frequency, inverse document frequency and field length normalisation contribute?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?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
What is the difference between text and keyword fields in Elasticsearch mappings, and why do teams often map a string field as both?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.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
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?Design reliable synchronisation of 30 million rows from PostgreSQL into OpenSearch, including the initial load and ongoing changes, with eventual consistency within 5 seconds.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?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
What are Lucene segments, and why are deletes and updates not applied in place?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?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
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?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?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?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?No question matches these choices.