Nest ES|QL queries using subqueries
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. This functionality is in technical preview and is ready for evaluation. Use with caution in production; it is not recommended for mission-critical workloads. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features. Specific Support terms apply. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
GA
9.5+
…
Generally available since 9.5
Preview in 9.4
A subquery is a complete ES|QL query wrapped in parentheses, nested inside another query. Each subquery runs independently and cannot reference columns from the outer query.
You can use subqueries in two places:
- In a
FROMcommand: each subquery runs its own pipeline and its rows are combined into the outer result set. - With
INorNOT IN: the subquery returns one column, or a tuple of columns matched by position, and can appear inWHERE. It can also appear inEVAL, and the per-aggregateWHEREofSTATSandINLINE STATSThe Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability Planned We plan to add this functionality in a future Elastic Stack update. Subject to changes. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes. .
A subquery starts with one of the following source commands:
FROM: read from an index pattern.TS: read from a time series index pattern.ROW: synthesize rows from literal values.
The source command can be followed by zero or more piped processing commands:
CHANGE_POINTCOMPLETIONDISSECTDROPENRICHEVALGROKINLINE STATSKEEPLIMITLOOKUP JOINMV_EXPANDRENAMERERANKSAMPLESORTSTATSWHERE
- Use subqueries in a
FROMcommand: combine result sets from independently processed sources. - Use subqueries with
INandNOT IN: filter or evaluate rows against another query. - Runtime search: how a full-text search after a
FROMwith subqueries contributes to_score.