Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
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.

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

The shortcut

Pick the language by who is typing and where: app code → Query DSL; exploring data step by step → ES|QL; Kibana's search bar → KQL; event sequences → EQL. For the DSL itself, ask of every clause "does it test a field, or hold other queries?"

Taking apart a query treeStep 1 of 4
  1. The root

    bool holds other queries → compound.

Drills

Answer fast — trust the rule.

quick drill

Which of these is a compound query?

quick drill

A security analyst wants "a failed login followed by a password reset on the same account". Which language is designed for that?

quick drill

What do you type into Kibana's search bar by default?

quick drill

Which statement about leaf queries is true?

Remember

  • Leaf queries test one field; compound queries combine other queries.
  • Query DSL for app code, ES|QL for pipelines, KQL in Kibana, EQL for event sequences.
  • Every query tree is leaves at the tips and compounds at the joints.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainLeaves and joints

Describe a Query DSL query for "fiction books with 'train' in the title, not out of stock", then label each part as a leaf or compound query and say which other query language a Kibana user would type the same idea in.