﻿---
title: Query DSL reference
description: Learn how Query DSL organizes queries in Elasticsearch, including leaf and compound clauses, query groups, and the expensive queries you can block.
url: https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/querydsl
products:
  - Elasticsearch
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Generally available
---

# Query DSL reference
<note>
  This section provides detailed **reference information**.Refer to the [Query DSL overview](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/4492/explore-analyze/query-filter/languages/querydsl) for overview and conceptual information about Query DSL.
</note>

Elasticsearch provides a full Query DSL (Domain Specific Language) based on JSON to define queries. You can start with a single clause, such as a `match` query, and combine clauses into larger queries as your searches grow. Think of the Query DSL as an AST (Abstract Syntax Tree) of queries.

## Query clause types

Query clauses fall into two types:
<definitions>
  <definition term="Leaf query clauses">
    Leaf query clauses look for a particular value in a particular field, such as the [`match`](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-match-query), [`term`](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-term-query) or [`range`](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-range-query) queries. These queries can be used by themselves.
  </definition>
  <definition term="Compound query clauses">
    Compound query clauses wrap other leaf **or** compound queries and are used to combine multiple queries in a logical fashion (such as the [`bool`](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-bool-query) or [`dis_max`](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-dis-max-query) query), or to alter their behaviour (such as the [`constant_score`](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-constant-score-query) query).
  </definition>
</definitions>

Query clauses behave differently depending on whether they are used in [query context or filter context](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-filter-context).

## Browse queries by group

Query DSL groups queries by the kind of search they run. Select a group to compare its queries:
- [Full-text queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/full-text-queries): Search analyzed text fields, such as the body of an email.
- [Term-level queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/term-level-queries): Find documents based on precise values in structured data, such as date ranges, IP addresses, prices, or product IDs.
- [Compound queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/compound-queries): Combine other queries, change their behavior, or switch from query to filter context.
- [Vector queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/vector-queries): Search vector fields to run semantic search.
- [Geo queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/geo-queries): Search `geo_point` and `geo_shape` fields.
- [Shape queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/shape-queries): Search `point` and `shape` fields that hold cartesian, non-geospatial data.
- [Joining queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/joining-queries): Query related documents with `nested` and parent-child joins.
- [Span queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/span-queries): Control the order and proximity of terms with low-level positional queries.
- [Specialized queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/specialized-queries): Use queries that don't fit the other groups.
- [Match all query](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-match-all-query): Match every document and give each a `_score` of `1.0`.


## Limit expensive queries

Certain types of queries generally run slowly because of the way they are implemented, which can affect the stability of the cluster. These queries fall into the following categories:
- Queries that need to do linear scans to identify matches:
  - [`script` queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-script-query)
- queries on [numeric](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/number), [date](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/date), [boolean](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/boolean), [ip](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/ip), [geo_point](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/geo-point) or [keyword](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/keyword) fields that are not indexed but have [doc values](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/doc-values) enabled
- Queries that have a high up-front cost:
  - [`fuzzy` queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-fuzzy-query) (except on [`wildcard`](/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/keyword#wildcard-field-type) fields)
- [`regexp` queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-regexp-query) (except on [`wildcard`](/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/keyword#wildcard-field-type) fields)
- [`prefix` queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-prefix-query) (except on [`wildcard`](/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/keyword#wildcard-field-type) fields, or on [`text`](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/text) fields with [`index_prefixes`](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/index-prefixes) enabled for supported prefix lengths)
- [`wildcard` queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-wildcard-query) (except on [`wildcard`](/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/keyword#wildcard-field-type) fields)
- [`range` queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-range-query) on [`text`](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/text) and [`keyword`](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/elasticsearch/mapping-reference/keyword) fields
- [Joining queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/joining-queries)
- Queries on [runtime fields](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/4492/manage-data/data-store/mapping/runtime-fields)
- Queries that might have a high per-document cost:
  - [`script_score` queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-script-score-query)
- [`percolate` queries](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-dsl-percolate-query)

Elasticsearch runs these queries by default. Whether you can block them depends on your deployment:
<applies-switch>
  <applies-item title="serverless: ga" applies-to="Elastic Cloud Serverless: Generally available">
    You can't block these queries. The `search.allow_expensive_queries` setting isn't configurable.
  </applies-item>

  <applies-item title="stack: ga" applies-to="Elastic Stack: Generally available">
    To block these queries, set `search.allow_expensive_queries` to `false` with the [cluster update settings API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-put-settings). This requires the `manage` [cluster privilege](/elastic/docs-builder/docs/4492/reference/elasticsearch/security-privileges#privileges-list-cluster). The setting is dynamic, so the change applies without a restart. While it is `false`, a search that includes one of the listed queries returns an error that names the setting, instead of running.
  </applies-item>
</applies-switch>


## Next steps

To learn Query DSL by example, refer to [Get started with Query DSL search and filters](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/full-text-filter-tutorial). To understand how query clauses score and filter documents, refer to [Query and filter context](https://www.elastic.co/elastic/docs-builder/docs/4492/reference/query-languages/query-dsl/query-filter-context).