﻿---
title: Sorting functions
description: PromQL sorting functions in Elasticsearch that sort instant-vector series by sample value.
url: https://www.elastic.co/elastic/docs-builder/docs/4561/reference/query-languages/promql/functions/sorting
products:
  - Elasticsearch
applies_to:
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Planned
---

# Sorting functions
These functions sort the series of an instant vector by sample value. Ordering is observable only on instant queries. Range queries return the series in their input order, without applying the requested ordering.

## `sort`

<applies-to>Elastic Stack: Planned</applies-to>
Sorts instant-vector series by sample value in ascending order. NaN values are sorted last.
Ordering is observable only on instant queries. Range queries return the series in their input order, without applying the requested ordering.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
sort(http_requests_total)
```

<note>
  **Differences from Prometheus**A call below the top level of the query, such as `abs(sort(x))`, isn't supported yet. Prometheus applies the ordering there too. On a range query the ordering is discarded in both, but Prometheus returns the series ordered by their labels, where Elasticsearch returns them in input order.
</note>


## `sort_desc`

<applies-to>Elastic Stack: Planned</applies-to>
Sorts instant-vector series by sample value in descending order. NaN values are sorted last.
Ordering is observable only on instant queries. Range queries return the series in their input order, without applying the requested ordering.
**Return type**
`instant_vector`
**Parameters**
<definitions>
  <definition term="v (instant_vector)">
    Instant vector input.
  </definition>
</definitions>

**Example**
```
sort_desc(http_requests_total)
```

<note>
  **Differences from Prometheus**A call below the top level of the query, such as `abs(sort(x))`, isn't supported yet. Prometheus applies the ordering there too. On a range query the ordering is discarded in both, but Prometheus returns the series ordered by their labels, where Elasticsearch returns them in input order.
</note>