CONSOLEify Stats Aggregation docs (#24373)

This commit is contained in:
Zachary Tong 2017-05-01 13:33:24 -04:00 committed by GitHub
parent 130f1a56f1
commit 4e49c618f2
2 changed files with 33 additions and 26 deletions

View File

@ -37,7 +37,6 @@ buildRestTests.expectedUnconvertedCandidates = [
'reference/aggregations/metrics/percentile-aggregation.asciidoc', 'reference/aggregations/metrics/percentile-aggregation.asciidoc',
'reference/aggregations/metrics/percentile-rank-aggregation.asciidoc', 'reference/aggregations/metrics/percentile-rank-aggregation.asciidoc',
'reference/aggregations/metrics/scripted-metric-aggregation.asciidoc', 'reference/aggregations/metrics/scripted-metric-aggregation.asciidoc',
'reference/aggregations/metrics/stats-aggregation.asciidoc',
'reference/aggregations/metrics/tophits-aggregation.asciidoc', 'reference/aggregations/metrics/tophits-aggregation.asciidoc',
'reference/cat/snapshots.asciidoc', 'reference/cat/snapshots.asciidoc',
'reference/cat/templates.asciidoc', 'reference/cat/templates.asciidoc',

View File

@ -9,12 +9,15 @@ Assuming the data consists of documents representing exams grades (between 0 and
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
POST /exams/_search?size=0
{ {
"aggs" : { "aggs" : {
"grades_stats" : { "stats" : { "field" : "grade" } } "grades_stats" : { "stats" : { "field" : "grade" } }
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
// TEST[setup:exams]
The above aggregation computes the grades statistics over all documents. The aggregation type is `stats` and the `field` setting defines the numeric field of the documents the stats will be computed on. The above will return the following: The above aggregation computes the grades statistics over all documents. The aggregation type is `stats` and the `field` setting defines the numeric field of the documents the stats will be computed on. The above will return the following:
@ -26,15 +29,16 @@ The above aggregation computes the grades statistics over all documents. The agg
"aggregations": { "aggregations": {
"grades_stats": { "grades_stats": {
"count": 6, "count": 2,
"min": 60, "min": 50.0,
"max": 98, "max": 100.0,
"avg": 78.5, "avg": 75.0,
"sum": 471 "sum": 150.0
} }
} }
} }
-------------------------------------------------- --------------------------------------------------
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
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. 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.
@ -44,9 +48,8 @@ Computing the grades stats based on a script:
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
POST /exams/_search?size=0
{ {
...,
"aggs" : { "aggs" : {
"grades_stats" : { "grades_stats" : {
"stats" : { "stats" : {
@ -59,14 +62,15 @@ Computing the grades stats based on a script:
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
// TEST[setup:exams]
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: 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:
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
POST /exams/_search?size=0
{ {
...,
"aggs" : { "aggs" : {
"grades_stats" : { "grades_stats" : {
"stats" : { "stats" : {
@ -81,6 +85,8 @@ This will interpret the `script` parameter as an `inline` script with the `painl
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
// TEST[setup:exams]
TIP: for indexed scripts replace the `file` parameter with an `id` parameter. TIP: for indexed scripts replace the `file` parameter with an `id` parameter.
@ -90,20 +96,17 @@ It turned out that the exam was way above the level of the students and a grade
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
POST /exams/_search?size=0
{ {
"aggs" : { "aggs" : {
... "grades_stats" : {
"stats" : {
"aggs" : { "field" : "grade",
"grades_stats" : { "script" : {
"stats" : { "lang": "painless",
"field" : "grade", "inline": "_value * params.correction",
"script" : "params" : {
"lang": "painless", "correction" : 1.2
"inline": "_value * params.correction",
"params" : {
"correction" : 1.2
}
} }
} }
} }
@ -111,6 +114,8 @@ It turned out that the exam was way above the level of the students and a grade
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
// TEST[setup:exams]
==== Missing value ==== Missing value
@ -120,6 +125,7 @@ had a value.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
POST /exams/_search?size=0
{ {
"aggs" : { "aggs" : {
"grades_stats" : { "grades_stats" : {
@ -131,5 +137,7 @@ had a value.
} }
} }
-------------------------------------------------- --------------------------------------------------
// CONSOLE
// TEST[setup:exams]
<1> Documents without a value in the `grade` field will fall into the same bucket as documents that have the value `0`. <1> Documents without a value in the `grade` field will fall into the same bucket as documents that have the value `0`.