ES|QL SUM function
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 This functionality is generally available and ready for production usage. 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
Generally available
Returns the sum of a numeric expression.
number
The sum of a numeric expression.
| number | result |
|---|---|
| aggregate_metric_double | double |
| dense_vector | dense_vector |
| double | double |
| exponential_histogram The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability Generally available since 9.4 This functionality is generally available and ready for production usage. Preview in 9.3 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. 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. | double |
| integer | long |
| long | long |
| tdigest The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability Generally available since 9.4 This functionality is generally available and ready for production usage. Preview in 9.3 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. 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. | double |
FROM employees
| STATS SUM(languages)
| SUM(languages):long |
|---|
| 281 |
The expression can use inline functions. For example, to calculate the sum of each employee’s maximum salary changes, apply the MV_MAX function to each row and then sum the results
FROM employees
| STATS total_salary_changes = SUM(MV_MAX(salary_change))
| total_salary_changes:double |
|---|
| 446.75 |
SUM can also operate on exponential_histogram fields, computing the sum of the values which were used to construct the histograms.
TS exp_histo_sample
| WHERE instance == "instance-0"
| STATS total = ROUND(SUM(responseTime), 2)
| total:double |
|---|
| 1472.74 |
SUM can also operate on tdigest and casted histogram fields, computing the sum of the values which were used to construct the digests.
TS histogram_timeseries_index
| WHERE instance == "instance-0"
| STATS total = ROUND(SUM(responseTime::tdigest), 2)
| total:double |
|---|
| 1472.74 |