Skip to content

Commit 7b59c69

Browse files
committed
CONSOLEify some more aggregation docs
Related #18160
1 parent 2254281 commit 7b59c69

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

docs/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ apply plugin: 'elasticsearch.docs-test'
2525
* entirely and have a party! There will be cake and everything.... */
2626
buildRestTests.expectedUnconvertedCandidates = [
2727
'reference/aggregations/bucket/iprange-aggregation.asciidoc',
28-
'reference/aggregations/bucket/missing-aggregation.asciidoc',
2928
'reference/aggregations/bucket/nested-aggregation.asciidoc',
3029
'reference/aggregations/bucket/range-aggregation.asciidoc',
3130
'reference/aggregations/bucket/reverse-nested-aggregation.asciidoc',
3231
'reference/aggregations/bucket/significantterms-aggregation.asciidoc',
3332
'reference/aggregations/bucket/terms-aggregation.asciidoc',
3433
'reference/aggregations/matrix/stats-aggregation.asciidoc',
35-
'reference/aggregations/metrics/cardinality-aggregation.asciidoc',
3634
'reference/aggregations/metrics/extendedstats-aggregation.asciidoc',
3735
'reference/aggregations/metrics/percentile-aggregation.asciidoc',
3836
'reference/aggregations/metrics/percentile-rank-aggregation.asciidoc',

docs/reference/aggregations/bucket/missing-aggregation.asciidoc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Example:
77

88
[source,js]
99
--------------------------------------------------
10+
POST /sales/_search?size=0
1011
{
1112
"aggs" : {
1213
"products_without_a_price" : {
@@ -15,6 +16,8 @@ Example:
1516
}
1617
}
1718
--------------------------------------------------
19+
// CONSOLE
20+
// TEST[setup:sales]
1821

1922
In the above example, we get the total number of products that do not have a price.
2023

@@ -24,11 +27,11 @@ Response:
2427
--------------------------------------------------
2528
{
2629
...
27-
28-
"aggs" : {
30+
"aggregations" : {
2931
"products_without_a_price" : {
30-
"doc_count" : 10
32+
"doc_count" : 00
3133
}
3234
}
3335
}
3436
--------------------------------------------------
37+
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]

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

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,34 @@ match a query:
1010

1111
[source,js]
1212
--------------------------------------------------
13+
POST /sales/_search?size=0
1314
{
1415
"aggs" : {
15-
"author_count" : {
16+
"type_count" : {
1617
"cardinality" : {
17-
"field" : "author"
18+
"field" : "type"
1819
}
1920
}
2021
}
2122
}
2223
--------------------------------------------------
24+
// CONSOLE
25+
// TEST[setup:sales]
26+
27+
Response:
28+
29+
[source,js]
30+
--------------------------------------------------
31+
{
32+
...
33+
"aggregations" : {
34+
"type_count" : {
35+
"value" : 3
36+
}
37+
}
38+
}
39+
--------------------------------------------------
40+
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
2341

2442
==== Precision control
2543

@@ -29,17 +47,20 @@ experimental[The `precision_threshold` option is specific to the current interna
2947

3048
[source,js]
3149
--------------------------------------------------
50+
POST /sales/_search?size=0
3251
{
3352
"aggs" : {
34-
"author_count" : {
53+
"type_count" : {
3554
"cardinality" : {
36-
"field" : "author_hash",
55+
"field" : "type",
3756
"precision_threshold": 100 <1>
3857
}
3958
}
4059
}
4160
}
4261
--------------------------------------------------
62+
// CONSOLE
63+
// TEST[setup:sales]
4364

4465
<1> The `precision_threshold` options allows to trade memory for accuracy, and
4566
defines a unique count below which counts are expected to be close to
@@ -159,40 +180,46 @@ however since hashes need to be computed on the fly.
159180

160181
[source,js]
161182
--------------------------------------------------
183+
POST /sales/_search?size=0
162184
{
163185
"aggs" : {
164-
"author_count" : {
186+
"type_promoted_count" : {
165187
"cardinality" : {
166188
"script": {
167189
"lang": "painless",
168-
"inline": "doc['author.first_name'].value + ' ' + doc['author.last_name'].value"
190+
"inline": "doc['type'].value + ' ' + doc['promoted'].value"
169191
}
170192
}
171193
}
172194
}
173195
}
174196
--------------------------------------------------
197+
// CONSOLE
198+
// TEST[setup:sales]
175199

176200
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:
177201

178202
[source,js]
179203
--------------------------------------------------
204+
POST /sales/_search?size=0
180205
{
181206
"aggs" : {
182-
"author_count" : {
207+
"type_promoted_count" : {
183208
"cardinality" : {
184209
"script" : {
185210
"file": "my_script",
186211
"params": {
187-
"first_name_field": "author.first_name",
188-
"last_name_field": "author.last_name"
212+
"type_field": "type",
213+
"promoted_field": "promoted"
189214
}
190215
}
191216
}
192217
}
193218
}
194219
}
195220
--------------------------------------------------
221+
// CONSOLE
222+
// TEST[skip:no script]
196223

197224
TIP: for indexed scripts replace the `file` parameter with an `id` parameter.
198225

@@ -204,6 +231,7 @@ had a value.
204231

205232
[source,js]
206233
--------------------------------------------------
234+
POST /sales/_search?size=0
207235
{
208236
"aggs" : {
209237
"tag_cardinality" : {
@@ -215,5 +243,6 @@ had a value.
215243
}
216244
}
217245
--------------------------------------------------
218-
246+
// CONSOLE
247+
// TEST[setup:sales]
219248
<1> Documents without a value in the `tag` field will fall into the same bucket as documents that have the value `N/A`.

0 commit comments

Comments
 (0)