﻿---
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/4492/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)
```

**Differences from Prometheus**
Supported in this version only as the outermost function of the query. Prometheus also applies an ordering requested inside an enclosing function call. On a range query the ordering is discarded either way, but Prometheus returns the series ordered by their labels, where Elasticsearch returns them in input order.

## `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)
```

**Differences from Prometheus**
Supported in this version only as the outermost function of the query. Prometheus also applies an ordering requested inside an enclosing function call. On a range query the ordering is discarded either way, but Prometheus returns the series ordered by their labels, where Elasticsearch returns them in input order.