How MDN’s site-search works
MDN's site search builds every page nightly in a GitHub Action, emitting index.json files. A Python script strips the HTML and bulk-publishes about 50,000 documents to a managed Elasticsearch cluster in roughly 3.5 minutes, deleting and recreating the index each day for simplicity. A Django endpoint queries it with elasticsearch-dsl, ranking by phrase and term boosts on title and body plus a Google Analytics-derived popularity score (rank = popularity*10 + score), and adds "Did you mean" suggestions. The cost of the daily rebuild is a brief window of incomplete results, softened by publishing the most popular en-US Web/ pages first.
Related posts
- How GitHub Docs’ new search works
GitHub Engineering mediumAdeptGitHub Docs replaced its in-memory Node.js site search, which loaded serialized indexes from the Git repo for eight languages and five versions, with Elasticsearch. Each search is sent as one query built from a matrix of fields (title, headings, content), two analyzers (explicit with no stemming or synonyms, and Snowball-stemmed) and match types (phrase, AND, OR, fuzzy). Each combination gets a distinct multiplicative boost, so exact title phrase matches rank highest and terms like `working-directory` aren't swamped by stemmed matches. Final scores are multiplied by (1 + normalized pageview popularity), and query execution stays around 20 ms server-side.
- How MDN’s autocomplete search works
Mozilla Hacks mediumAdeptMDN Web Docs' autocomplete search runs entirely in the browser. It lazy-loads a Brotli-compressed JSON index of every document title per locale (11,690 en-US titles, 144KB over the wire) only when the user focuses or hovers the search box or presses `/`. FlexSearch builds an in-memory index that is reused across keystrokes, and downshift handles the accessible React dropdown. Ranking comes from pre-sorting the index by relative pageview popularity at build time, so FlexSearch's matches keep that natural order. Typing `/` first switches to VS Code-style fuzzy matching on URL paths, which also works offline for content authors on a local preview server.
- A brief history of code search at GitHub
GitHub Engineering mediumAdeptGitHub's code search evolved from a public-only Solr index plus `git grep` for private repos, to a decade-long Elasticsearch deployment that grew to 162 nodes, 1.25PB of storage and over 53 billion indexed files. Natural-language text analysis fits source code poorly. GitHub's custom tokenizer dropped punctuation and could not do substring or regex matching. An experiment that indexed special characters made indexing 43-100% slower, grew the index 18-28% and slowed typical queries about 2.1x. A short-lived exact-match beta also failed to balance its resource cost against corpus growth. Existing trigram engines like Russ Cox's and Zoekt also fell short at GitHub's scale, so GitHub built Blackbird, a bespoke engine targeting sub-second p95 global exact-match and regex queries without using much more resources than the Elasticsearch cluster.
- Managing Elasticsearch Reindex at Scale: Performance, Reliability, and Observability
Palantir mediumAdeptPalantir's Gotham document store rebuilds Elasticsearch indices from its transactional database (the source of truth) rather than using Elasticsearch's _reindex API, so search keeps serving live traffic throughout. The design writes to both the primary index and a shadow index, swaps them using aliases, and resolves conflicting writes with external_gte versioning. A background loop compares persisted metadata against actual cluster state and queues repairs. Later improvements added a parallel paging and indexing job runner with resumable checkpoints, three-way batch limits (document count, memory, batches per run), crash-safe idempotent state machines for index lifecycle operations, and layered logs, metrics and diagnostics for observability.
- The search for speed in Figma
Figma mediumAdept
Figma's search slowness traced mostly to its own stack, not OpenSearch: OpenSearch's headline 8 ms metric was per-shard time, and only the "took" field in responses reveals overall query latency, which accounted for under 30% of API time. Fixes included reordering and slimming Ruby permission checks, repairing a database connection setup bug that also sped up the rest of Figma, and trimming index size by 50% and then 90% so the data fit in the OS page cache. Load tests with a custom Go benchmark showed AWS sizing guidance suited log workloads, not latency-sensitive search. Cutting shards from 450 to 180 and moving to nodes with less CPU and more RAM paid off, while concurrent segment search hurt. Overall API latency fell about 60%, peak QPS rose over 50%, and cost dropped more than 50%.