From 486154e40a164ce282bc7c15e363a66049ae0061 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 23 Jan 2017 10:04:53 -0500 Subject: [PATCH] Docs: CONSOLE-ify value_count aggregation docs Adds the `VIEW IN CONSOLE` and `COPY AS CURL` links to the snippets in the `value_count` docs and causes the build to execute the snippets for testing. Release #18160 --- docs/build.gradle | 1 - .../metrics/valuecount-aggregation.asciidoc | 34 +++++++++++-------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/docs/build.gradle b/docs/build.gradle index 85f86d58bec5f..d7e7f364cab1b 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -48,7 +48,6 @@ buildRestTests.expectedUnconvertedCandidates = [ 'reference/aggregations/metrics/stats-aggregation.asciidoc', 'reference/aggregations/metrics/sum-aggregation.asciidoc', 'reference/aggregations/metrics/tophits-aggregation.asciidoc', - 'reference/aggregations/metrics/valuecount-aggregation.asciidoc', 'reference/aggregations/pipeline.asciidoc', 'reference/aggregations/pipeline/avg-bucket-aggregation.asciidoc', 'reference/aggregations/pipeline/bucket-script-aggregation.asciidoc', diff --git a/docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc b/docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc index 925f5426187b8..8b67d64c87791 100644 --- a/docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc @@ -8,12 +8,15 @@ one might be interested in the number of values the average is computed over. [source,js] -------------------------------------------------- +POST /sales/_search?size=0 { "aggs" : { - "grades_count" : { "value_count" : { "field" : "grade" } } + "types_count" : { "value_count" : { "field" : "type" } } } } -------------------------------------------------- +// CONSOLE +// TEST[setup:sales] Response: @@ -21,14 +24,14 @@ Response: -------------------------------------------------- { ... - "aggregations": { - "grades_count": { - "value": 10 + "types_count": { + "value": 7 } } } -------------------------------------------------- +// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/] The name of the aggregation (`grades_count` above) also serves as the key by which the aggregation result can be retrieved from the returned response. @@ -39,36 +42,35 @@ Counting the values generated by a script: [source,js] -------------------------------------------------- +POST /sales/_search?size=0 { - ..., - "aggs" : { - "grades_count" : { - "value_count" : { + "type_count" : { + "value_count" : { "script" : { - "inline" : "doc['grade'].value", - "lang" : "painless" + "inline" : "doc['type'].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" : { - "grades_count" : { - "value_count" : { + "grades_count" : { + "value_count" : { "script" : { "file": "my_script", "params" : { - "field" : "grade" + "field" : "type" } } } @@ -76,5 +78,7 @@ This will interpret the `script` parameter as an `inline` script with the `painl } } -------------------------------------------------- +// CONSOLE +// TEST[setup:sales] TIP: for indexed scripts replace the `file` parameter with an `id` parameter.