Skip to content

Document ES|QL SORT by expression#143705

Merged
wchaparro merged 5 commits intomainfrom
docs/esql-sort-by-expression-115011
Mar 6, 2026
Merged

Document ES|QL SORT by expression#143705
wchaparro merged 5 commits intomainfrom
docs/esql-sort-by-expression-115011

Conversation

@wchaparro
Copy link
Copy Markdown
Member

Summary

Documents that the ES|QL SORT command accepts any expression as a sort key, not only column names (feature added in 8.14.0, see #107158).

Changes

  • SORT command (commands/sort.md via layout snippet): Updated intro, syntax, and parameters to use "expression" instead of "column"; clarified that sort keys can be column names, functions (e.g. length(field), year(date)), or arithmetic. Added a Sort by expression example subsection with SORT length(first_name) DESC.
  • Limitations: Aligned SORT limitation wording with "expression" terminology.

Fixes #115011

Made with Cursor

Update SORT command docs to state that sort keys can be any expression
(column, function, or arithmetic), not only column names. Add syntax,
parameter description, and a 'Sort by expression' example. Align
limitations.md wording with expression terminology.

Fixes #115011

Made-with: Cursor
@wchaparro wchaparro requested a review from a team as a code owner March 5, 2026 18:29
@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v9.4.0 labels Mar 5, 2026
@wchaparro wchaparro requested a review from craigtaverner March 5, 2026 18:30
@wchaparro wchaparro added the :Analytics/ES|QL AKA ESQL label Mar 5, 2026
@elasticsearchmachine elasticsearchmachine added Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) and removed needs:triage Requires assignment of a team area label labels Mar 5, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@wchaparro wchaparro added the >docs General docs changes label Mar 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

🔍 Preview links for changed docs

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

ℹ️ Important: Docs version tagging

👋 Thanks for updating the docs! Just a friendly reminder that our docs are now cumulative. This means all 9.x versions are documented on the same page and published off of the main branch, instead of creating separate pages for each minor version.

We use applies_to tags to mark version-specific features and changes.

Expand for a quick overview

When to use applies_to tags:

✅ At the page level to indicate which products/deployments the content applies to (mandatory)
✅ When features change state (e.g. preview, ga) in a specific version
✅ When availability differs across deployments and environments

What NOT to do:

❌ Don't remove or replace information that applies to an older version
❌ Don't add new information that applies to a specific version without an applies_to tag
❌ Don't forget that applies_to tags can be used at the page, section, and inline level

🤔 Need help?

Copy link
Copy Markdown
Contributor

@ivancea ivancea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the ES|QL documentation to reflect that SORT supports sorting by arbitrary expressions (not just column names), aligning docs with the feature introduced in 8.14.0.

Changes:

  • Update SORT command intro/syntax/parameter wording from “column” to “expression”, and add an example showing sorting by an expression.
  • Adjust ES|QL limitations wording to match the updated SORT “expression” terminology.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
docs/reference/query-languages/esql/limitations.md Updates SORT limitation wording to refer to expressions evaluating to spatial types.
docs/reference/query-languages/esql/_snippets/commands/layout/sort.md Documents expression-based sorting, updates syntax/parameter docs, and adds a “Sort by expression” example.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +18 to +20
[function](/reference/query-languages/esql/esql-functions-operators.md#esql-functions) (for example,
`length(field)`, `year(date)`), or an arithmetic expression (for example, `salary * 2`).
The expression is evaluated per row and the result is used for ordering.
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

year(date) is not an ES|QL function in this docs set (existing docs use DATE_EXTRACT("year", date) for year extraction). Using year(date) here will mislead readers and makes the example inconsistent with the function reference—please replace it with a valid ES|QL date function call (e.g., DATE_EXTRACT("year", date)).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. updated

Comment on lines +24 to +25
The `SORT` processing command sorts a table on one or more expressions. You can sort by any
expression, not only column names—for example, `length(first_name)` or `year(hire_date)`.
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description example uses year(hire_date), but there doesn't appear to be an ES|QL year() function in the docs (year extraction is documented via DATE_EXTRACT("year", <date>)). Please update this example to a valid ES|QL function to avoid confusing users.

Copilot uses AI. Check for mistakes.
wchaparro and others added 3 commits March 6, 2026 12:05
…sort.md

Co-authored-by: Iván Cea Fontenla <ivancea96@outlook.com>
Replace year(date) with DATE_EXTRACT("year", date) so examples
match the documented ES|QL date functions.

Made-with: Cursor
@wchaparro wchaparro merged commit 70140a7 into main Mar 6, 2026
14 checks passed
@wchaparro wchaparro deleted the docs/esql-sort-by-expression-115011 branch March 6, 2026 18:10
sidosera pushed a commit to sidosera/elasticsearch that referenced this pull request Mar 6, 2026
* Document ES|QL SORT by expression

Update SORT command docs to state that sort keys can be any expression
(column, function, or arithmetic), not only column names. Add syntax,
parameter description, and a 'Sort by expression' example. Align
limitations.md wording with expression terminology.

Fixes elastic#115011

Made-with: Cursor

* Update docs/reference/query-languages/esql/_snippets/commands/layout/sort.md

Co-authored-by: Iván Cea Fontenla <ivancea96@outlook.com>

* Use DATE_EXTRACT for year in SORT expression examples

Replace year(date) with DATE_EXTRACT("year", date) so examples
match the documented ES|QL date functions.

Made-with: Cursor

---------

Co-authored-by: Iván Cea Fontenla <ivancea96@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >docs General docs changes Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing docs for ES|QL sorting by expressions

5 participants