CONSOLE-ify global-aggregation.asciidoc

Adds the `VIEW IN CONSOLE` and `COPY AS CURL` links to the example
`global` aggregation. Also improves the example by adding a
non-`global` aggregation to compare it to.

Relates to 
This commit is contained in:
Nik Everett 2017-01-20 14:26:10 -05:00
parent 4ec4bad908
commit 8c856eaa9f
2 changed files with 26 additions and 11 deletions
docs
build.gradle
reference/aggregations/bucket

@ -30,7 +30,6 @@ buildRestTests.expectedUnconvertedCandidates = [
'reference/aggregations/bucket/filter-aggregation.asciidoc',
'reference/aggregations/bucket/geodistance-aggregation.asciidoc',
'reference/aggregations/bucket/geohashgrid-aggregation.asciidoc',
'reference/aggregations/bucket/global-aggregation.asciidoc',
'reference/aggregations/bucket/histogram-aggregation.asciidoc',
'reference/aggregations/bucket/iprange-aggregation.asciidoc',
'reference/aggregations/bucket/missing-aggregation.asciidoc',

@ -1,18 +1,22 @@
[[search-aggregations-bucket-global-aggregation]]
=== Global Aggregation
Defines a single bucket of all the documents within the search execution context. This context is defined by the indices and the document types you're searching on, but is *not* influenced by the search query itself.
Defines a single bucket of all the documents within the search execution
context. This context is defined by the indices and the document types you're
searching on, but is *not* influenced by the search query itself.
NOTE: Global aggregators can only be placed as top level aggregators (it makes no sense to embed a global aggregator
within another bucket aggregator)
NOTE: Global aggregators can only be placed as top level aggregators because
it doesn't make sense to embed a global aggregator within another
bucket aggregator.
Example:
[source,js]
--------------------------------------------------
POST /sales/_search?size=0
{
"query" : {
"match" : { "title" : "shirt" }
"match" : { "type" : "t-shirt" }
},
"aggs" : {
"all_products" : {
@ -20,15 +24,21 @@ Example:
"aggs" : { <2>
"avg_price" : { "avg" : { "field" : "price" } }
}
}
},
"t_shirts": { "avg" : { "field" : "price" } }
}
}
--------------------------------------------------
// CONSOLE
// TEST[setup:sales]
<1> The `global` aggregation has an empty body
<2> The sub-aggregations that are registered for this `global` aggregation
The above aggregation demonstrates how one would compute aggregations (`avg_price` in this example) on all the documents in the search context, regardless of the query (in our example, it will compute the average price over all products in our catalog, not just on the "shirts").
The above aggregation demonstrates how one would compute aggregations
(`avg_price` in this example) on all the documents in the search context,
regardless of the query (in our example, it will compute the average price over
all products in our catalog, not just on the "shirts").
The response for the above aggregation:
@ -36,16 +46,22 @@ The response for the above aggregation:
--------------------------------------------------
{
...
"aggregations" : {
"all_products" : {
"doc_count" : 100, <1>
"doc_count" : 7, <1>
"avg_price" : {
"value" : 56.3
"value" : 140.71428571428572 <2>
}
},
"t_shirts": {
"value" : 128.33333333333334 <3>
}
}
}
--------------------------------------------------
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,"hits": $body.hits,/]
<1> The number of documents that were aggregated (in our case, all documents within the search context)
<1> The number of documents that were aggregated (in our case, all documents
within the search context)
<2> The average price of all products in the index
<3> The average price of all t-shirts