Skip to content

Commit

Permalink
Docs: CONSOLE-ify value_count aggregation docs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nik9000 committed Jan 23, 2017
1 parent 9e71e09 commit 486154e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
1 change: 0 additions & 1 deletion docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
34 changes: 19 additions & 15 deletions docs/reference/aggregations/metrics/valuecount-aggregation.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,30 @@ 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:

[source,js]
--------------------------------------------------
{
...
"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.
Expand All @@ -39,42 +42,43 @@ 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"
}
}
}
}
}
}
--------------------------------------------------
// CONSOLE
// TEST[setup:sales]

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

0 comments on commit 486154e

Please sign in to comment.