Sorting functions
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability We plan to add this functionality in a future Elastic Stack update. Subject to changes. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
Planned
Planned
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.
The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability Planned We plan to add this functionality in a future Elastic Stack update. Subject to changes. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
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.
The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability Planned We plan to add this functionality in a future Elastic Stack update. Subject to changes. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes. Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability Preview This functionality is in technical preview and is ready for evaluation. Use with caution in production; it is not recommended for mission-critical workloads. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features. Specific Support terms apply. Serverless interfaces and procedures might differ from classic Elastic Stack deployments.
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.
The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability Planned We plan to add this functionality in a future Elastic Stack update. Subject to changes. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes. Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability Preview This functionality is in technical preview and is ready for evaluation. Use with caution in production; it is not recommended for mission-critical workloads. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features. Specific Support terms apply. Serverless interfaces and procedures might differ from classic Elastic Stack deployments.
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.
The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability Planned We plan to add this functionality in a future Elastic Stack update. Subject to changes. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
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.