|
6 | 6 |
|
7 | 7 | [source,esql]
|
8 | 8 | ----
|
9 |
| -STATS [column1 =] expression1[, ..., [columnN =] expressionN] |
| 9 | +STATS [column1 =] expression1[, ..., [columnN =] expressionN] |
10 | 10 | [BY grouping_expression1[, ..., grouping_expressionN]]
|
11 | 11 | ----
|
12 | 12 |
|
@@ -39,8 +39,8 @@ NOTE: `STATS` without any groups is much much faster than adding a group.
|
39 | 39 |
|
40 | 40 | NOTE: Grouping on a single expression is currently much more optimized than grouping
|
41 | 41 | on many expressions. In some tests we have seen grouping on a single `keyword`
|
42 |
| - column to be five times faster than grouping on two `keyword` columns. Do |
43 |
| - not try to work around this by combining the two columns together with |
| 42 | + column to be five times faster than grouping on two `keyword` columns. Do |
| 43 | + not try to work around this by combining the two columns together with |
44 | 44 | something like <<esql-concat>> and then grouping - that is not going to be
|
45 | 45 | faster.
|
46 | 46 |
|
@@ -80,14 +80,36 @@ include::{esql-specs}/stats.csv-spec[tag=statsCalcMultipleValues]
|
80 | 80 | include::{esql-specs}/stats.csv-spec[tag=statsCalcMultipleValues-result]
|
81 | 81 | |===
|
82 | 82 |
|
83 |
| -It's also possible to group by multiple values (only supported for long and |
84 |
| -keyword family fields): |
| 83 | +[[esql-stats-mv-group]] |
| 84 | +If the grouping key is multivalued then the input row is in all groups: |
| 85 | + |
| 86 | +[source.merge.styled,esql] |
| 87 | +---- |
| 88 | +include::{esql-specs}/stats.csv-spec[tag=mv-group] |
| 89 | +---- |
| 90 | +[%header.monospaced.styled,format=dsv,separator=|] |
| 91 | +|=== |
| 92 | +include::{esql-specs}/stats.csv-spec[tag=mv-group-result] |
| 93 | +|=== |
| 94 | + |
| 95 | +It's also possible to group by multiple values: |
85 | 96 |
|
86 | 97 | [source,esql]
|
87 | 98 | ----
|
88 | 99 | include::{esql-specs}/stats.csv-spec[tag=statsGroupByMultipleValues]
|
89 | 100 | ----
|
90 | 101 |
|
| 102 | +If the all grouping keys are multivalued then the input row is in all groups: |
| 103 | + |
| 104 | +[source.merge.styled,esql] |
| 105 | +---- |
| 106 | +include::{esql-specs}/stats.csv-spec[tag=multi-mv-group] |
| 107 | +---- |
| 108 | +[%header.monospaced.styled,format=dsv,separator=|] |
| 109 | +|=== |
| 110 | +include::{esql-specs}/stats.csv-spec[tag=multi-mv-group-result] |
| 111 | +|=== |
| 112 | + |
91 | 113 | Both the aggregating functions and the grouping expressions accept other
|
92 | 114 | functions. This is useful for using `STATS...BY` on multivalue columns.
|
93 | 115 | For example, to calculate the average salary change, you can use `MV_AVG` to
|
|
0 commit comments