Sorting functions
These functions sort the series of an instant vector by sample value (sort and sort_desc) or by listed label values (sort_by_label and sort_by_label_desc). Ordering is observable only on instant queries. Range queries return the series in their input order, without applying the requested ordering.
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
v(instant_vector)- Instant vector input.
Example
sort(http_requests_total)
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.
Sorts instant-vector series by the values of the given labels in natural ascending order. Missing labels compare as the empty string.
Ordering is observable only on instant queries. Range queries return the series in their input order, without applying the requested ordering. Label comparison uses natural order, with sequences of digits compared numerically.
Return type
instant_vector
Parameters
v(instant_vector)- Instant vector input.
label(scalar)- Name of a label to sort by (repeatable).
Example
sort_by_label(http_requests_total, "job", "instance")
Differences from Prometheus
- A call below the top level of the query, such as
abs(sort_by_label(x, "job")), isn't supported yet. Prometheus applies the ordering there too. - When the requested labels are equal, ties are broken by series identity, approximating Prometheus
labels.Compare. The order can differ in edge cases, such as a series missing a label or labels of non-string types. - 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.
- Sequences of digits that are numerically equal but differ in leading zeros (for example,
item1anditem01), and empty label values, get a stable order rather than Prometheus's unstable natural sort order. - Sequences of digits longer than about 20 digits are still compared numerically, where Prometheus falls back to text comparison.
Sorts instant-vector series by the values of the given labels in natural descending order. Missing labels compare as the empty string.
Ordering is observable only on instant queries. Range queries return the series in their input order, without applying the requested ordering. Label comparison uses natural order, with sequences of digits compared numerically.
Return type
instant_vector
Parameters
v(instant_vector)- Instant vector input.
label(scalar)- Name of a label to sort by (repeatable).
Example
sort_by_label_desc(http_requests_total, "job", "instance")
Differences from Prometheus
- A call below the top level of the query, such as
abs(sort_by_label(x, "job")), isn't supported yet. Prometheus applies the ordering there too. - When the requested labels are equal, ties are broken by series identity, approximating Prometheus
labels.Compare. The order can differ in edge cases, such as a series missing a label or labels of non-string types. - 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.
- Sequences of digits that are numerically equal but differ in leading zeros (for example,
item1anditem01), and empty label values, get a stable order rather than Prometheus's unstable natural sort order. - Sequences of digits longer than about 20 digits are still compared numerically, where Prometheus falls back to text comparison.
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
v(instant_vector)- Instant vector input.
Example
sort_desc(http_requests_total)
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.