ES|QL ROUND_TO function
field- The numeric value to round. If
null, the function returnsnull. 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 |
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 |