Skip to content

Commit

Permalink
CONSOLEify some more aggregation docs
Browse files Browse the repository at this point in the history
Related #18160
  • Loading branch information
polyfractal committed May 16, 2017
1 parent 5ac2ddd commit a2845c8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
2 changes: 0 additions & 2 deletions docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ apply plugin: 'elasticsearch.docs-test'
* entirely and have a party! There will be cake and everything.... */
buildRestTests.expectedUnconvertedCandidates = [
'reference/aggregations/bucket/iprange-aggregation.asciidoc',
'reference/aggregations/bucket/missing-aggregation.asciidoc',
'reference/aggregations/bucket/nested-aggregation.asciidoc',
'reference/aggregations/bucket/range-aggregation.asciidoc',
'reference/aggregations/bucket/reverse-nested-aggregation.asciidoc',
'reference/aggregations/bucket/significantterms-aggregation.asciidoc',
'reference/aggregations/bucket/terms-aggregation.asciidoc',
'reference/aggregations/matrix/stats-aggregation.asciidoc',
'reference/aggregations/metrics/cardinality-aggregation.asciidoc',
'reference/aggregations/metrics/extendedstats-aggregation.asciidoc',
'reference/aggregations/metrics/percentile-aggregation.asciidoc',
'reference/aggregations/metrics/percentile-rank-aggregation.asciidoc',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Example:

[source,js]
--------------------------------------------------
POST /sales/_search?size=0
{
"aggs" : {
"products_without_a_price" : {
Expand All @@ -15,6 +16,8 @@ Example:
}
}
--------------------------------------------------
// CONSOLE
// TEST[setup:sales]

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

Expand All @@ -24,11 +27,11 @@ Response:
--------------------------------------------------
{
...
"aggs" : {
"aggregations" : {
"products_without_a_price" : {
"doc_count" : 10
"doc_count" : 00
}
}
}
--------------------------------------------------
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,34 @@ match a query:

[source,js]
--------------------------------------------------
POST /sales/_search?size=0
{
"aggs" : {
"author_count" : {
"type_count" : {
"cardinality" : {
"field" : "author"
"field" : "type"
}
}
}
}
--------------------------------------------------
// CONSOLE
// TEST[setup:sales]

Response:

[source,js]
--------------------------------------------------
{
...
"aggregations" : {
"type_count" : {
"value" : 3
}
}
}
--------------------------------------------------
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]

==== Precision control

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

[source,js]
--------------------------------------------------
POST /sales/_search?size=0
{
"aggs" : {
"author_count" : {
"type_count" : {
"cardinality" : {
"field" : "author_hash",
"field" : "type",
"precision_threshold": 100 <1>
}
}
}
}
--------------------------------------------------
// CONSOLE
// TEST[setup:sales]

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

[source,js]
--------------------------------------------------
POST /sales/_search?size=0
{
"aggs" : {
"author_count" : {
"type_promoted_count" : {
"cardinality" : {
"script": {
"lang": "painless",
"inline": "doc['author.first_name'].value + ' ' + doc['author.last_name'].value"
"inline": "doc['type'].value + ' ' + doc['promoted'].value"
}
}
}
}
}
--------------------------------------------------
// CONSOLE
// TEST[setup:sales]

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]
--------------------------------------------------
POST /sales/_search?size=0
{
"aggs" : {
"author_count" : {
"type_promoted_count" : {
"cardinality" : {
"script" : {
"file": "my_script",
"params": {
"first_name_field": "author.first_name",
"last_name_field": "author.last_name"
"type_field": "type",
"promoted_field": "promoted"
}
}
}
}
}
}
--------------------------------------------------
// CONSOLE
// TEST[skip:no script]

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

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

[source,js]
--------------------------------------------------
POST /sales/_search?size=0
{
"aggs" : {
"tag_cardinality" : {
Expand All @@ -215,5 +243,6 @@ had a value.
}
}
--------------------------------------------------

// CONSOLE
// TEST[setup:sales]
<1> Documents without a value in the `tag` field will fall into the same bucket as documents that have the value `N/A`.

0 comments on commit a2845c8

Please sign in to comment.