elasticsearch/docs/reference/esql/processing-commands/sort.asciidoc
Nik Everett 1256a49c3a
ESQL: Move description of commands in docs (#110714)
This copies the first line of the description of each command to just
under the syntax so that it's "in order", before the `Parameters`
section. That way if you are reading from top to bottom you see:
```
syntax
short description
parameter names and descriptions
long description
examples
```

I've also removed the `Description` section entirely if the description
was just one sentence. So in some cases that just isn't `long
description`.
2024-07-11 08:31:35 -04:00

63 lines
1.4 KiB
Text

[discrete]
[[esql-sort]]
=== `SORT`
The `SORT` processing command sorts a table on one or more columns.
**Syntax**
[source,esql]
----
SORT column1 [ASC/DESC][NULLS FIRST/NULLS LAST][, ..., columnN [ASC/DESC][NULLS FIRST/NULLS LAST]]
----
*Parameters*
`columnX`::
The column to sort on.
*Description*
The `SORT` processing command sorts a table on one or more columns.
The default sort order is ascending. Use `ASC` or `DESC` to specify an explicit
sort order.
Two rows with the same sort key are considered equal. You can provide additional
sort expressions to act as tie breakers.
Sorting on multivalued columns uses the lowest value when sorting ascending and
the highest value when sorting descending.
By default, `null` values are treated as being larger than any other value. With
an ascending sort order, `null` values are sorted last, and with a descending
sort order, `null` values are sorted first. You can change that by providing
`NULLS FIRST` or `NULLS LAST`.
*Examples*
[source,esql]
----
include::{esql-specs}/docs.csv-spec[tag=sort]
----
Explicitly sorting in ascending order with `ASC`:
[source,esql]
----
include::{esql-specs}/docs.csv-spec[tag=sortDesc]
----
Providing additional sort expressions to act as tie breakers:
[source,esql]
----
include::{esql-specs}/docs.csv-spec[tag=sortTie]
----
Sorting `null` values first using `NULLS FIRST`:
[source,esql]
----
include::{esql-specs}/docs.csv-spec[tag=sortNullsFirst]
----