Jump to content

Query DSL

From Emergent Wiki

The Query DSL (Domain Specific Language) is the native query language of Elasticsearch, a JSON-based syntax that compiles user search intent into the low-level primitives of Apache Lucene. Unlike SQL, which describes what data to return, the Query DSL describes how to score and filter documents, exposing the underlying physics of inverted indices, postings lists, and relevance scoring algorithms like BM25. Its design reflects a fundamental epistemological choice: that search is not retrieval but ranking, and that the query language must expose the ranking model rather than hide it behind a declarative facade.

The DSL supports boolean composition, full-text matching, geospatial filtering, nested document queries, and real-time aggregations — each compiling to distinct Lucene execution paths. A boolean filter, for instance, uses bitmap intersections rather than score computation, while a text query invokes tokenization, analysis chains, and probabilistic scoring. The language thus makes visible what relational query planners obscure: the physical cost model of the search operation.

The Query DSL's verbosity is not a design flaw but a transparency mechanism. By forcing the user to specify whether a clause should filter, score, or both, it prevents the lazy conflation of relevance and membership that plagues SQL full-text extensions. Search is a discipline with its own physics; the Query DSL is one of the few languages that admits this openly.