Skip to the workspace
Pebellslearn by building
Documents and Leaf Queries  ›  Lesson

Query DSL and the Other Query Languages

Query DSL 12 minThe Query DSL builds searches from leaf queries that test one field and compound queries that combine them, while ES|QL, SQL, KQL, Lucene syntax and EQL serve other users.

elasticsearch / Query DSL and the Other Query Languages

Explore each scene at your own pace.

01 · The rule

The rule

Query DSL and the Other Query Languages

"Fiction under 20" can be written six different ways against Elasticsearch. That sounds chaotic until you notice each language was built for a different person: an app developer, an analyst, someone typing in a search bar. The main one — and the one this course uses — is the Query DSL.

The rule

Leaf queries test one field; compound queries combine other queries.

The Query DSL (domain-specific language) is JSON sent to _search. Its building blocks come in two kinds:

  • Leaf queries look for a value in a single field: match, term, range, exists, prefix, wildcard, ids.
  • Compound queries wrap other queries and decide how they combine: bool is the everyday one; others include constant_score, boosting, dis_max and function_score.
GET /books/_search
{
  "query": {
    "bool": {
      "must":   [ { "match": { "title": "garden" } } ],
      "filter": [ { "range": { "price": { "lt": 20 } } } ]
    }
  }
}

Here bool is compound; match and range are leaves. Any query tree, however large, is leaves at the tips and compounds at the joints.

The same question in the other languages:

  • ES|QL — a piped language sent to POST /_query: start FROM books, then add one step at a time. Built for analysts exploring data.
  • SQL — SELECT title FROM books WHERE genre = 'fiction' AND price < 20, sent to POST /_sql. For people who already know SQL.
  • KQL — genre : fiction and price < 20. What you type into Kibana's search bar.
  • Lucene syntax — genre:fiction AND price:<20. Used by the query_string query and older tools.
  • EQL — describes a sequence of events, such as a login followed by a download. Built for security work on ordered events over time.

An ES|QL pipeline, one step per line:

FROM books
| WHERE genre == "fiction" AND price < 20
| SORT price
| KEEP title, price
| LIMIT 10
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.