elasticsearch/docs/reference/query-languages
Nik Everett 45bfaab448
ESQL: ROUND_TO function (#128278)
Creates a `ROUND_TO` function that rounds it's input to one of the
provided values. Like so:
```
ROUND_TO(v, 0, 5000, 10000, 20000, 40000, 100000)

   v   | ROUND_TO
     0 | 0
   100 | 0
  6000 | 5000
 45001 | 40000
999999 | 100000
```

For some sequences of numbers you could do this with the `/` operator -
but for arbitrary sequences of numbers you needed `CASE` which is quite
slow. And hard to read!

Rewriting the example above would look like:
```
CASE (
  v <   5000,     0,
  v <  10000,  5000,
  v <  20000, 10000,
  v <  40000, 20000,
  v < 100000, 40000,
  100000
)
```

Even better, this is *fast*:
```
        (operation)  Mode  Cnt    Score   Error  Units
round_to_4_via_case  avgt    7  138.124 ± 0.738  ns/op
         round_to_4  avgt    7    0.805 ± 0.011  ns/op
         round_to_3  avgt    7    0.739 ± 0.011  ns/op
         round_to_2  avgt    7    0.651 ± 0.009  ns/op
         date_trunc  avgt    7    2.425 ± 0.018  ns/op
```

I've included a comparison to `DATE_TRUNC` above because we should be
able to rewrite `DATE_TRUNC` into `ROUND_TO` when we know the date range
of the index. This doesn't do it now, but it should be possible.
2025-05-23 10:14:30 -04:00
..
eql [docs] Fix various syntax and rendering errors (#127062) 2025-04-24 17:57:03 +02:00
esql ESQL: ROUND_TO function (#128278) 2025-05-23 10:14:30 -04:00
images [DOCS] Fix broken images (#126648) 2025-04-11 19:04:08 -07:00
query-dsl [DOCS] Replace irregular whitespaces in docs (#128199) 2025-05-20 16:20:22 +02:00
sql [DOCS] Replace irregular whitespaces in docs (#128199) 2025-05-20 16:20:22 +02:00
eql.md Restructure query-languages docs files for clarity (#124797) 2025-03-17 17:58:58 +01:00
esql.md [DOCS][9.x] Improve ESQL reference docs information architecture (#127248) 2025-04-25 09:54:45 +02:00
index.md [Reference] Revisit query language landing page (#127632) 2025-05-07 08:44:49 +02:00
kql.md Fix broken cross-repo links, versions in search connectors docker instructions (#123700) 2025-02-28 16:02:54 +01:00
querydsl.md Restructure query-languages docs files for clarity (#124797) 2025-03-17 17:58:58 +01:00
sql.md Restructure query-languages docs files for clarity (#124797) 2025-03-17 17:58:58 +01:00
toc.yml [DOCS][9.x] Improve ESQL reference docs information architecture (#127248) 2025-04-25 09:54:45 +02:00