Type to search.

ES|QL ROUND_TO function

Serverless Preview

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.

Stack Preview 9.1+

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Preview since 9.1

    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.

Rounds down to one of a list of fixed points.

Embedded
Embedded
field
The numeric value to round. If null, the function returns null.
points

Remaining rounding points. Must be constants.

Rounds down to one of a list of fixed points.

field points result
date date date
date_nanos date_nanos date_nanos
double double double
double integer double
double long double
integer double double
integer integer integer
integer long long
long double double
long integer long
long long long
ES|QL
FROM employees
| STATS COUNT(*) BY birth_window=ROUND_TO(
    birth_date,
    "1900-01-01T00:00:00Z"::DATETIME,
    "1950-01-01T00:00:00Z"::DATETIME,
    "1955-01-01T00:00:00Z"::DATETIME,
    "1960-01-01T00:00:00Z"::DATETIME,
    "1965-01-01T00:00:00Z"::DATETIME,
    "1970-01-01T00:00:00Z"::DATETIME,
    "1975-01-01T00:00:00Z"::DATETIME
)
| SORT birth_window ASC
COUNT(*):long birth_window:datetime
27 1950-01-01T00:00:00Z
29 1955-01-01T00:00:00Z
33 1960-01-01T00:00:00Z
1 1965-01-01T00:00:00Z
10 null