Skip to content

Commit bbc1639

Browse files
authored
ESQL: Explain confusing query (#135848) (#136298)
This links to an explanation about a very confusing query that you can write in ESQL. It've decided to link to github here to because this query is so deeply at the edge that you need to know that you are dealing with hackers now. Closes #134792
1 parent c5f28a1 commit bbc1639

File tree

1 file changed

+15
-6
lines changed
  • docs/reference/query-languages/esql/_snippets/commands/layout

1 file changed

+15
-6
lines changed

docs/reference/query-languages/esql/_snippets/commands/layout/stats-by.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ and then grouping - that is not going to be faster.
7575
::::
7676

7777

78-
**Examples**
78+
### Examples
7979

8080
Calculating a statistic and grouping by the values of another column:
8181

@@ -104,15 +104,17 @@ optional as well:
104104
:::{include} ../examples/stats.csv-spec/aggFilteringNoGroup.md
105105
:::
106106

107-
$$$esql-stats-mv-group$$$
108-
If the grouping key is multivalued then the input row is in all groups:
107+
It’s also possible to group by multiple values:
109108

110-
:::{include} ../examples/stats.csv-spec/mv-group.md
109+
:::{include} ../examples/stats.csv-spec/statsGroupByMultipleValues.md
111110
:::
112111

113-
It’s also possible to group by multiple values:
112+
$$$esql-stats-mv-group$$$
113+
#### Multivalued inputs
114114

115-
:::{include} ../examples/stats.csv-spec/statsGroupByMultipleValues.md
115+
If the grouping key is multivalued then the input row is in all groups:
116+
117+
:::{include} ../examples/stats.csv-spec/mv-group.md
116118
:::
117119

118120
If all the grouping keys are multivalued then the input row is in all groups:
@@ -132,6 +134,11 @@ key. If you want to send the group key to the function then `MV_EXPAND` first:
132134
:::{include} ../examples/stats.csv-spec/mv-group-values-expand.md
133135
:::
134136

137+
Refer to [elasticsearch/issues/134792](https://github.com/elastic/elasticsearch/issues/134792#issuecomment-3361168090)
138+
for an even more in depth explanation.
139+
140+
#### Multivalue functions
141+
135142
Both the aggregating functions and the grouping expressions accept other
136143
functions. This is useful for using `STATS` on multivalue columns.
137144
For example, to calculate the average salary change, you can use `MV_AVG` to
@@ -147,6 +154,8 @@ letter of their last name:
147154
:::{include} ../examples/stats.csv-spec/docsStatsByExpression.md
148155
:::
149156

157+
#### Naming
158+
150159
Specifying the output column name is optional. If not specified, the new column
151160
name is equal to the expression. The following query returns a column named
152161
`AVG(salary)`:

0 commit comments

Comments
 (0)