Problem
Issues search on GitHub accepted only a flat list of terms and filters, joined by an implicit AND. Users had asked for OR across any field for nearly a decade; a 2021 change covered only comma-separated label values. Rewriting the core of a search that handles nearly 2000 queries per second is risky, and many queries are bookmarked, shared and linked in documents, so a change in how old queries are read breaks real workflows.
Example from the article: assignee:@me label:support new-project meant "assigned to me AND labeled support AND containing new-project"; OR worked only across label values, not across other fields.
Solution in brief
Replace the flat-list parser with a grammar-based parser that builds an abstract syntax tree (AST), then walk the tree to build a nested Elasticsearch bool query. The grammar still accepts the old syntax. The new module was compared with the old one on live traffic in the background, then released in stages.
Questions this case answers
- How to replace a query-parsing and retrieval module that serves heavy traffic while keeping every existing query working and avoiding a performance regression
- How to extend a flat filter syntax to recursive boolean logic and map it onto a search engine's native query language
- How to add nested AND/OR query syntax to a product search without breaking saved and shared queries?
- How to parse a user search string with filters and parentheses into a tree and turn it into an Elasticsearch bool query?
Tools and methods
- Parslet (PEG grammar) — parses the string into an AST; one grammar for old and new syntax
- Elasticsearch bool query — target; AND, OR, NOT map to must, should, should_not
- Scientist — GitHub's Ruby library to compare old and new code paths
- Shadow mode — 1% of searches rerun on the new module, differences logged
- Canary rollout — GraphQL API and repository Issues tab first, then the dashboard and REST API
Google or a one-time email code. No password.