## SORT

The `SORT` command in ES|QL is a processing command that sorts a table based on one or more columns. The default sort order is ascending, but you can specify an explicit sort order using `ASC` or `DESC`. 

In cases where two rows have the same sort key, they are considered equal. However, you can provide additional sort expressions to act as tie breakers. When sorting on multivalued columns, the lowest value is used when sorting in ascending order and the highest value when sorting in descending order.

By default, null values are treated as being larger than any other value. This means that with an ascending sort order, null values are sorted last, and with a descending sort order, null values are sorted first. You can change this by providing `NULLS FIRST` or `NULLS LAST`.

### Examples

Here are some examples of how to use the `SORT` command in ES|QL:

1. Sorting by height in ascending order (default):

    ```esql
FROM employees
| KEEP first_name, last_name, height
| SORT height
```

2. Explicitly sorting in descending order with `DESC`:

    ```esql
FROM employees
| KEEP first_name, last_name, height
| SORT height DESC
```

3. Providing additional sort expressions to act as tie breakers:

    ```esql
FROM employees
| KEEP first_name, last_name, height
| SORT height DESC, first_name ASC
```

4. Sorting null values first using `NULLS FIRST`:

    ```esql
FROM employees
| KEEP first_name, last_name, height
| SORT first_name ASC NULLS FIRST
```

Please note that the `SORT` command does not support sorting on spatial types (`geo_point`, `geo_shape`, `cartesian_point`, `cartesian_shape`).