elasticsearch/docs/reference/esql/processing-commands/stats.asciidoc
Nik Everett 82d67dc289 Docs for aggregation functions (ESQL-1268)
This adds docs for all of ESQL's aggregation functions. Hopefully from
here on out we can add the docs as we add new functions.

I've created a few tagged regions in the aggs docs themselves so we can
include them into the ESQL docs.

---------

Co-authored-by: Abdon Pijpelink <abdon.pijpelink@elastic.co>
2023-06-14 09:23:34 -05:00

44 lines
1.1 KiB
Text

[[esql-stats-by]]
=== `STATS ... BY`
Use `STATS ... BY` to group rows according to a common value and calculate one
or more aggregated values over the grouped rows.
[source.merge.styled,esql]
----
include::{esql-specs}/docs.csv-spec[tag=stats]
----
[%header.monospaced.styled,format=dsv,separator=|]
|===
include::{esql-specs}/docs.csv-spec[tag=stats-result]
|===
If `BY` is omitted, the output table contains exactly one row with the
aggregations applied over the entire dataset:
[source.merge.styled,esql]
----
include::{esql-specs}/docs.csv-spec[tag=statsWithoutBy]
----
[%header.monospaced.styled,format=dsv,separator=|]
|===
include::{esql-specs}/docs.csv-spec[tag=statsWithoutBy-result]
|===
It's possible to calculate multiple values:
[source,esql]
----
include::{esql-specs}/docs.csv-spec[tag=statsCalcMultipleValues]
----
It's also possible to group by multiple values (only supported for long and
keyword family fields):
[source,esql]
----
include::{esql-specs}/docs.csv-spec[tag=statsGroupByMultipleValues]
----
The following aggregation functions are supported:
include::../aggregation-functions.asciidoc[tag=functions]