grouping.asciidoc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-functions-grouping]]
  4. === Grouping Functions
  5. beta[]
  6. Functions for creating special __grouping__s (also known as _bucketing_); as such these need to be used
  7. as part of the <<sql-syntax-group-by, grouping>>.
  8. [[sql-functions-grouping-histogram]]
  9. ==== `HISTOGRAM`
  10. .Synopsis
  11. [source, sql]
  12. ----
  13. HISTOGRAM ( numeric_exp<1>, numeric_interval<2>)
  14. HISTOGRAM ( date_exp<3>, date_time_interval<4>)
  15. ----
  16. *Input*:
  17. <1> numeric expression (typically a field)
  18. <2> numeric interval
  19. <3> date/time expression (typically a field)
  20. <4> date/time <<sql-functions-datetime-interval, interval>>
  21. *Output*: non-empty buckets or groups of the given expression divided according to the given interval
  22. .Description
  23. The histogram function takes all matching values and divides them into buckets with fixed size matching the given interval, using (roughly) the following formula:
  24. [source, sql]
  25. ----
  26. bucket_key = Math.floor(value / interval) * interval
  27. ----
  28. `Histogram` can be applied on either numeric fields:
  29. ["source","sql",subs="attributes,callouts,macros"]
  30. ----
  31. include-tagged::{sql-specs}/docs.csv-spec[histogramNumeric]
  32. ----
  33. or date/time fields:
  34. ["source","sql",subs="attributes,callouts,macros"]
  35. ----
  36. include-tagged::{sql-specs}/docs.csv-spec[histogramDate]
  37. ----