Elasticsearch Query Language (Query DSL) Reference

The Elasticsearch Query DSL is a JSON-based query language used to search and aggregate data in an Elasticsearch index. It supports full-text search, structured filters, geo queries, vector (kNN) search, and a rich aggregation framework, all expressed as nested JSON objects. The Query DSL is the primary interface for application search, log analytics, and dashboards built on Elasticsearch and OpenSearch.

The DSL is sometimes informally called "Query DSL" or "Search DSL". A different SQL-like language, "EQL" (Event Query Language), exists for security-style sequence detection - it is not the same thing. This page indexes the JSON Query DSL.

Query DSL Anatomy

Every search request goes to _search and carries a query clause:

GET /my-index/_search
{
  "query": {
    "bool": {
      "must":   [ { "match": { "title": "elasticsearch" } } ],
      "filter": [ { "term": { "status": "published" } } ]
    }
  },
  "size": 10,
  "from": 0,
  "sort": [ { "published_at": "desc" } ],
  "aggs": {
    "by_category": { "terms": { "field": "category" } }
  }
}

Two distinctions to keep clear:

  • Query context (inside must, should) computes a relevance score (_score).
  • Filter context (inside filter, must_not) is yes/no, does not score, and is cached.

If you do not need scoring, put the clause in filter. It is faster and the results are cacheable.

Available Elasticsearch Query Types

Term-level queries (exact matches, no analysis):

Full-text queries (analyzed against text fields):

Compound queries (combine other queries):

Joining queries (parent-child and nested):

Geo queries:

Scripting and vector search:

Available Elasticsearch Aggregation Types

Metric Aggregations:

Bucket Aggregations:

Pipeline Aggregations:

Matrix Aggregations:

Geo Aggregations:

Other Aggregations:

Operating Query DSL in Production

The Query DSL is expressive enough to write queries that look reasonable and quietly destroy a cluster. Wildcard queries with leading wildcards, regex queries against text fields, deep from/size pagination, and unbounded terms aggregations are the most common offenders. Pulse Query Analytics profiles real query traffic against your cluster, surfaces the slowest and most expensive queries, and recommends DSL changes (filter context, field rewrites, runtime field push-down) that cut latency without an application rewrite.

Frequently Asked Questions

Q: What is the difference between Elasticsearch Query DSL and EQL?
A: Query DSL is the JSON query language used by every search request - the query, aggs, sort blocks. EQL (Event Query Language) is a separate, SQL-like syntax for sequence and correlation detection in security telemetry. Most application search uses Query DSL.

Q: When should I use filter context vs query context?
A: Use filter context (filter, must_not) for yes/no conditions where relevance scoring does not matter. Filter clauses skip scoring and are cached. Use query context (must, should) when the clause should contribute to _score.

Q: What is the difference between match and term queries?
A: match analyzes the input the same way the field was analyzed at index time (lowercasing, tokenizing) and is the right choice for text fields. term matches the literal value with no analysis and is the right choice for keyword, numeric, date, and boolean fields.

Q: How do I write a query that combines multiple conditions?
A: Wrap them in a bool query with must, should, must_not, and filter clauses. must and filter are AND, should is OR (with optional minimum_should_match), must_not is NOT.

Q: Does Elasticsearch support SQL?
A: Yes, via the SQL API (POST /_sql?format=txt) which translates a subset of SQL into Query DSL. For ad-hoc analysis it is convenient; for production application queries, write Query DSL directly to get full control over filters, scoring, and aggregations.

Q: How is the Elasticsearch Query DSL different from KQL?
A: KQL (Kibana Query Language) is a simplified query syntax used in Kibana's search bar (status:200 AND host:web*). It compiles down to Query DSL at execution time. Use KQL for interactive filtering in Kibana, Query DSL for application code.

Subscribe to the Pulse Newsletter

Get early access to new Pulse features, insightful blogs & exclusive events , webinars, and workshops.

We use cookies to provide an optimized user experience and understand our traffic. To learn more, read our use of cookies; otherwise, please choose 'Accept Cookies' to continue using our website.