Skip to content

Find eligible results through an index

11 min reading

Trace ingestion, indexing, freshness and filtering to query results

Page details

System Design · Store and find data

11 min reading · 24 min with practice

Sources

Published · Last edited:

Prerequisite: Store large objects separately from metadata. For basics, use the independent System Design foundations.

More
20px

Hypothetical scenario. A visitor searches Northwind by description instead of choosing a known product. Dev can find a matching description, but Maya withdraws that product before the response is delivered. Priya asks whether a relevant match is still an eligible answer.

Dev: “The index found text that matches the request.”

Maya: “Show how withdrawal and the selected price rules survive that search path.”

Follow source identity into a derived search view, then separate candidate discovery, ranking and required eligibility. Search explicitly extends the browsing brief; keep its workload distinct from the earlier detail and listing reads.

What question is the visitor asking the index?

A known-key lookup asks for a specific identity. An ordered category query selects a defined membership. Text search asks which records might satisfy a stated information need. Exact identifiers, words, phrases and prefixes need different treatment; one operator should not be assumed to express every user intention.

The earlier B-tree lesson explained ordered access paths. A text-oriented inverted index instead associates analyzed terms with records that contain them. The analysis process determines how source text becomes searchable terms. Choices about case, word forms and language affect what matches; they are application behavior worth evaluating.

Do not assume that finding matching words establishes a useful result. Ranking chooses among candidates according to the selected relevance approach. Eligibility decides whether a candidate may be returned at all. A highly ranked withdrawn product is still ineligible under Northwind’s declared catalogue rule.

Build a derived view with source identity

The authoritative product record supplies the identity, current version, public description and market/eligibility information selected for indexing. Ingestion transforms those fields into the search representation. Retain the source version or another usable lineage record so a delayed update can be identified rather than blindly replacing newer content.

An index update is a separate operation from changing the source database. A product change may commit before search can observe it. This gap needs a declared freshness objective and recovery path. The next module introduces queues and delivery contracts that can carry this work; here we describe the state that those mechanisms must maintain.

Search candidates remain subject to current eligibilityVersioned source records feed an analyzed index. A text query produces ranked candidates. Required market and eligibility checks determine the records returned with eligible current fields and ready image references.Source versionPublic productAnalyzed indexDerived viewQuery + rankingCandidatesRequired eligibility checksThen return the selected page
Index presence and current permission to show a product are separate facts.

Open the searchable record and its rebuild boundary

Hypothetical scenario. Tokenize Q7's description into terms such as brass and valve. The inverted index maps each term to candidate document identities; the stored document also carries source revision, market eligibility and analyzer identity. A match is candidate discovery, not permission to display an obsolete price.

Open the searchable record and its rebuild boundary — selected design evidence
Index elementExamplePurpose
Postingvalve → Q7Candidate discovery
Document evidenceQ7, source rev12, analyzer a2Trace result provenance
Candidate checkpointsnapshot S, applied watermark TBound rebuild completeness
The candidate combines a coherent snapshot with later changes before a reader pointer moves.The candidate combines a coherent snapshot with later changes before a reader pointer moves. Source snapshot S to Candidate index: bulk source records; Changes after S to Candidate index: versioned updates + removals.Source snapshot SCandidate indexChanges after Sbulk source recordsversioned updates + removals
The candidate combines a coherent snapshot with later changes before a reader pointer moves. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

Build a replacement index from a source snapshot at boundary S and capture later changes without a gap. Apply the stream in a version-aware way, including withdrawals, until the candidate reaches an agreed source boundary. Refresh visibility and source-stream progress are distinct: an ingested event may not yet be searchable.

A reader switch requires more than equal document counts. Compare known source versions, tombstones, permission behavior and representative queries. A rollback to an old index must not bypass a current eligibility check or revive withdrawn results. Keep source evidence independent from the analyzer version: changing tokenization may improve discovery while leaving the underlying record old.

Combine relevance and required filters

Northwind can search descriptions while requiring the selected market and active-product state. A relevance signal should not be allowed to outweigh a mandatory condition. In Elasticsearch, the Boolean query documentation distinguishes scoring clauses from required filters. This gives a concrete mechanism for expressing part of that separation.

The mechanism is only as current as its indexed fields. If the source withdrew a product after the index’s last update, an indexed active flag can be stale. Depending on the consequence and freshness contract, the serving path may need a current eligibility check or another way to prevent stale candidates from being exposed.

Prices deserve similar care. Returning a current price by identity can preserve one display requirement while the search index remains older. But a search filter based on an indexed price may still select the wrong candidates. Replacing the displayed value after selection does not retroactively make the earlier predicate correct.

Work through candidate loss before returning a page

Hypothetical worked example. Choose twenty ranked candidates for a first page. A current check finds six withdrawn products and four products unavailable in the selected market. Two records belong to both rejected groups. The number rejected is 6 + 4 − 2 = 8, so twenty candidates leave 20 − 8 = 12 eligible results.

Simply subtracting six and four separately would count the overlap twice. More importantly, claiming that the category contains only twelve eligible matches would confuse an inspected candidate window with the complete search space. Later candidates may qualify.

Northwind must decide whether a page means up to twenty eligible results, exactly twenty when enough exist, or another explicitly bounded behavior. A serving process might fetch further candidates under a deadline and continuation policy. It should distinguish reaching a true end from stopping because its inspection or time budget was exhausted.

Extend the workload ledger explicitly

For a separate search-sizing exercise, choose one search request for each of the earlier five visits per second. This adds 5 × 1 = 5 search requests per second to the original fifteen catalogue requests. Combined request demand is 15 + 5 = 20 per second before retries and any separately fetched image objects.

If each search inspects the selected twenty candidates once, candidate checks are 5 × 20 = 100 per second. If the checks are implemented as one batched request per search, that does not mean one hundred network requests. Logical records checked, batches and storage operations remain different quantities.

Keep the selected two product changes per second for an ingestion estimate. A five-second unprocessed interval represents 2 × 5 = 10 pending changes under the uniform-rate model. That count does not establish the oldest product age or prove that all changes have equal processing cost. Track the age of relevant unfinished work alongside counts.

A fast response can contain irrelevant products; a relevant result can contain stale or withdrawn data. Evaluate these properties separately and then connect them to the original user action. Use a declared set of queries and expected judgments rather than inventing an unexplained relevance percentage.

Query analysis also needs examples that expose intended distinctions. A product identifier should not necessarily be stemmed like natural-language text. A prefix typed into a suggestion box is not the same query as a complete description. The later complete search case develops suggestions and evaluation; this first lesson establishes the pipeline and eligibility boundary.

In the wild: query clauses do not refresh evidence

Elastic’s public query documentation explains ways to combine text matching and filters. It is evidence about actual query semantics, not evidence that Northwind’s source and index are synchronized. Both the ingestion state and the serving checks need observable contracts.

The older Elasticsearch book on the resource shelf remains useful for index and analysis concepts, but its historical APIs should not be treated as current implementation instructions. Use current vendor documentation for syntax and behavior. This keeps a useful conceptual source without implying that an old software version is the deployed target.

When an old projection survives a withdrawal

Hypothetical failure scenario. Northwind removes a promotion product from its source records, but the corresponding search update fails. The old index entry remains highly ranked and a cached snippet still advertises the promotion. Product detail correctly says unavailable; discovery continues sending visitors toward a misleading result.

The remedy spans ingestion and serving. Retain failed update evidence and recover the projection, while enforcing the chosen current eligibility rule before exposing a result. Hiding only the detail page does not repair the snippet, result counts or suggestion surface. Identify every derived representation that carries the withdrawn claim.

Choose search for a discovery need

Use a search index when matching, ranking or query composition justifies maintaining another representation. Keep simple known-key or category access where that answers the product need. A separate search service adds ingestion, lag, version and recovery obligations alongside its discovery capabilities.

Northwind now has a complete storage-module question for background work: how do product changes reach replicas, object publication and the search projection without making the visitor wait for every slow step? The next lesson introduces a queue and distinguishes accepting that work from completing its effect.

Challenge the proposed mechanism

Two indexes contain the same number of documents. Can their reader pointers be exchanged safely?

Reveal the design reasoning

No. One may contain an obsolete Q7 while omitting another record. Validate version coverage, removals, current permissions and query behavior at the selected boundary. Keep the old index only if rollback preserves these obligations.

Decision and reconsideration: Use index watermarks and version-bound evidence for migration. Rebuild success means eligible coverage, not matching totals.

Review the returned result

  1. Six withdrawn and four wrong-market candidates overlap in two records. How many of twenty remain?

    Count the union once

    Eight are rejected: 6 + 4 − 2. Twelve remain. That count describes the selected candidate window, not all possible eligible matches.

  2. The displayed price is refreshed after search. Does that make an earlier indexed price filter current?

    Separate selection from presentation

    No. The filter may already have admitted or excluded candidates using old values. A current display field does not repair selection based on stale evidence.

  3. One hundred candidates are checked per second. Must that create one hundred network requests?

    Distinguish records and batches

    No. The selected five searches can batch twenty checks each. Count candidate work, request fan-out and storage operations separately when estimating the path.

The search index is useful only while source changes reach it under an explicit freshness contract. Page 19 takes that maintenance work off the seller’s waiting path and asks what an early acknowledgement can honestly promise.

Northwind decision log

Keep source identity and version attached to the derived search representation.
Separate ranking from required current eligibility and price-selection rules.
Carry unfinished ingestion work into the queue and delivery-contract module.

Go deeper: a derived searchable view