Skip to content

Commit 268923e

Browse files
committed
CONSOLEify extended_stats docs
Related #18160
1 parent aafd7f9 commit 268923e

File tree

2 files changed

+44
-28
lines changed

2 files changed

+44
-28
lines changed

docs/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ buildRestTests.expectedUnconvertedCandidates = [
3131
'reference/aggregations/bucket/significantterms-aggregation.asciidoc',
3232
'reference/aggregations/bucket/terms-aggregation.asciidoc',
3333
'reference/aggregations/matrix/stats-aggregation.asciidoc',
34-
'reference/aggregations/metrics/extendedstats-aggregation.asciidoc',
3534
'reference/aggregations/metrics/percentile-aggregation.asciidoc',
3635
'reference/aggregations/metrics/percentile-rank-aggregation.asciidoc',
3736
'reference/aggregations/metrics/scripted-metric-aggregation.asciidoc',

docs/reference/aggregations/metrics/extendedstats-aggregation.asciidoc

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ Assuming the data consists of documents representing exams grades (between 0 and
99

1010
[source,js]
1111
--------------------------------------------------
12+
GET /exams/_search
1213
{
14+
"size": 0,
1315
"aggs" : {
1416
"grades_stats" : { "extended_stats" : { "field" : "grade" } }
1517
}
1618
}
1719
--------------------------------------------------
20+
// CONSOLE
21+
// TEST[setup:exams]
1822

1923
The above aggregation computes the grades statistics over all documents. The aggregation type is `extended_stats` and the `field` setting defines the numeric field of the documents the stats will be computed on. The above will return the following:
2024

@@ -25,23 +29,24 @@ The above aggregation computes the grades statistics over all documents. The agg
2529
...
2630
2731
"aggregations": {
28-
"grade_stats": {
29-
"count": 9,
30-
"min": 72,
31-
"max": 99,
32-
"avg": 86,
33-
"sum": 774,
34-
"sum_of_squares": 67028,
35-
"variance": 51.55555555555556,
36-
"std_deviation": 7.180219742846005,
32+
"grades_stats": {
33+
"count": 2,
34+
"min": 50.0,
35+
"max": 100.0,
36+
"avg": 75.0,
37+
"sum": 150.0,
38+
"sum_of_squares": 12500.0,
39+
"variance": 625.0,
40+
"std_deviation": 25.0,
3741
"std_deviation_bounds": {
38-
"upper": 100.36043948569201,
39-
"lower": 71.63956051430799
42+
"upper": 125.0,
43+
"lower": 25.0
4044
}
4145
}
4246
}
4347
}
4448
--------------------------------------------------
49+
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
4550

4651
The name of the aggregation (`grades_stats` above) also serves as the key by which the aggregation result can be retrieved from the returned response.
4752

@@ -52,7 +57,9 @@ three standard deviations, you can set `sigma` in the request:
5257

5358
[source,js]
5459
--------------------------------------------------
60+
GET /exams/_search
5561
{
62+
"size": 0,
5663
"aggs" : {
5764
"grades_stats" : {
5865
"extended_stats" : {
@@ -63,6 +70,8 @@ three standard deviations, you can set `sigma` in the request:
6370
}
6471
}
6572
--------------------------------------------------
73+
// CONSOLE
74+
// TEST[setup:exams]
6675
<1> `sigma` controls how many standard deviations +/- from the mean should be displayed
6776

6877
`sigma` can be any non-negative double, meaning you can request non-integer values such as `1.5`. A value of `0` is valid, but will simply
@@ -82,9 +91,9 @@ Computing the grades stats based on a script:
8291

8392
[source,js]
8493
--------------------------------------------------
94+
GET /exams/_search
8595
{
86-
...,
87-
96+
"size": 0,
8897
"aggs" : {
8998
"grades_stats" : {
9099
"extended_stats" : {
@@ -97,14 +106,16 @@ Computing the grades stats based on a script:
97106
}
98107
}
99108
--------------------------------------------------
109+
// CONSOLE
110+
// TEST[setup:exams]
100111

101112
This will interpret the `script` parameter as an `inline` script with the `painless` script language and no script parameters. To use a file script use the following syntax:
102113

103114
[source,js]
104115
--------------------------------------------------
116+
GET /exams/_search
105117
{
106-
...,
107-
118+
"size": 0,
108119
"aggs" : {
109120
"grades_stats" : {
110121
"extended_stats" : {
@@ -119,34 +130,36 @@ This will interpret the `script` parameter as an `inline` script with the `painl
119130
}
120131
}
121132
--------------------------------------------------
133+
// CONSOLE
134+
// TEST[setup:exams,stored_example_script]
122135

123136
===== Value Script
124137

125138
It turned out that the exam was way above the level of the students and a grade correction needs to be applied. We can use value script to get the new stats:
126139

127140
[source,js]
128141
--------------------------------------------------
142+
GET /exams/_search
129143
{
144+
"size": 0,
130145
"aggs" : {
131-
...
132-
133-
"aggs" : {
134-
"grades_stats" : {
135-
"extended_stats" : {
136-
"field" : "grade",
137-
"script" : {
138-
"lang" : "painless",
139-
"source": "_value * params.correction",
140-
"params" : {
141-
"correction" : 1.2
142-
}
146+
"grades_stats" : {
147+
"extended_stats" : {
148+
"field" : "grade",
149+
"script" : {
150+
"lang" : "painless",
151+
"source": "_value * params.correction",
152+
"params" : {
153+
"correction" : 1.2
143154
}
144155
}
145156
}
146157
}
147158
}
148159
}
149160
--------------------------------------------------
161+
// CONSOLE
162+
// TEST[setup:exams]
150163

151164
==== Missing value
152165

@@ -156,7 +169,9 @@ had a value.
156169

157170
[source,js]
158171
--------------------------------------------------
172+
GET /exams/_search
159173
{
174+
"size": 0,
160175
"aggs" : {
161176
"grades_stats" : {
162177
"extended_stats" : {
@@ -167,5 +182,7 @@ had a value.
167182
}
168183
}
169184
--------------------------------------------------
185+
// CONSOLE
186+
// TEST[setup:exams]
170187

171188
<1> Documents without a value in the `grade` field will fall into the same bucket as documents that have the value `0`.

0 commit comments

Comments
 (0)