diff --git a/docs/reference/search/aggregations/bucket/datehistogram-aggregation.asciidoc b/docs/reference/search/aggregations/bucket/datehistogram-aggregation.asciidoc index fd84398bce6..ce817ac5ae4 100644 --- a/docs/reference/search/aggregations/bucket/datehistogram-aggregation.asciidoc +++ b/docs/reference/search/aggregations/bucket/datehistogram-aggregation.asciidoc @@ -111,19 +111,21 @@ Response: -------------------------------------------------- { "aggregations": { - "articles_over_time": [ - { - "key_as_string": "2013-02-02", - "key": 1328140800000, - "doc_count": 1 - }, - { - "key_as_string": "2013-03-02", - "key": 1330646400000, - "doc_count": 2 - }, - ... - ] + "articles_over_time": { + "buckets": [ + { + "key_as_string": "2013-02-02", + "key": 1328140800000, + "doc_count": 1 + }, + { + "key_as_string": "2013-03-02", + "key": 1330646400000, + "doc_count": 2 + }, + ... + ] + } } } -------------------------------------------------- diff --git a/docs/reference/search/aggregations/bucket/daterange-aggregation.asciidoc b/docs/reference/search/aggregations/bucket/daterange-aggregation.asciidoc index 721cbc3fc46..710f3acf2c3 100644 --- a/docs/reference/search/aggregations/bucket/daterange-aggregation.asciidoc +++ b/docs/reference/search/aggregations/bucket/daterange-aggregation.asciidoc @@ -34,18 +34,20 @@ Response: ... "aggregations": { - "range": [ - { - "to": 1.3437792E+12, - "to_as_string": "08-2012", - "doc_count": 7 - }, - { - "from": 1.3437792E+12, - "from_as_string": "08-2012", - "doc_count": 2 - } - ] + "range": { + "buckets": [ + { + "to": 1.3437792E+12, + "to_as_string": "08-2012", + "doc_count": 7 + }, + { + "from": 1.3437792E+12, + "from_as_string": "08-2012", + "doc_count": 2 + } + ] + } } } -------------------------------------------------- diff --git a/docs/reference/search/aggregations/bucket/geodistance-aggregation.asciidoc b/docs/reference/search/aggregations/bucket/geodistance-aggregation.asciidoc index 6d7e8c3dff8..db4cd4a9de5 100644 --- a/docs/reference/search/aggregations/bucket/geodistance-aggregation.asciidoc +++ b/docs/reference/search/aggregations/bucket/geodistance-aggregation.asciidoc @@ -28,24 +28,26 @@ Response: -------------------------------------------------- { "aggregations": { - "rings": [ - { - "unit": "km", - "to": 100.0, - "doc_count": 3 - }, - { - "unit": "km", - "from": 100.0, - "to": 300.0, - "doc_count": 1 - }, - { - "unit": "km", - "from": 300.0, - "doc_count": 7 - } - ] + "rings" : { + "buckets": [ + { + "unit": "km", + "to": 100.0, + "doc_count": 3 + }, + { + "unit": "km", + "from": 100.0, + "to": 300.0, + "doc_count": 1 + }, + { + "unit": "km", + "from": 300.0, + "doc_count": 7 + } + ] + } } } -------------------------------------------------- diff --git a/docs/reference/search/aggregations/bucket/histogram-aggregation.asciidoc b/docs/reference/search/aggregations/bucket/histogram-aggregation.asciidoc index 2765e2389ae..6f5518d65cc 100644 --- a/docs/reference/search/aggregations/bucket/histogram-aggregation.asciidoc +++ b/docs/reference/search/aggregations/bucket/histogram-aggregation.asciidoc @@ -34,20 +34,22 @@ And the following may be the response: -------------------------------------------------- { "aggregations": { - "prices": [ - { - "key": 0, - "doc_count": 2 - }, - { - "key": 50, - "doc_count": 4 - }, - { - "key": 150, - "doc_count": 3 - } - ] + "prices" : { + "buckets": [ + { + "key": 0, + "doc_count": 2 + }, + { + "key": 50, + "doc_count": 4 + }, + { + "key": 150, + "doc_count": 3 + } + ] + } } } -------------------------------------------------- @@ -75,24 +77,26 @@ Response: -------------------------------------------------- { "aggregations": { - "prices": [ - { - "key": 0, - "doc_count": 2 - }, - { - "key": 50, - "doc_count": 4 - }, - { - "key" : 100, - "doc_count" : 0 - }, - { - "key": 150, - "doc_count": 3 - } - ] + "prices" : { + "buckets": [ + { + "key": 0, + "doc_count": 2 + }, + { + "key": 50, + "doc_count": 4 + }, + { + "key" : 100, + "doc_count" : 0 + }, + { + "key": 150, + "doc_count": 3 + } + ] + } } } -------------------------------------------------- @@ -187,29 +191,31 @@ NOTE: The special value `0` can be used to add empty buckets to the response b { "aggregations": { "prices": { - "0": { - "key": 0, - "doc_count": 2 - }, - "50": { - "key": 50, - "doc_count": 0 - }, - "150": { - "key": 150, - "doc_count": 3 - }, - "200": { - "key": 150, - "doc_count": 0 - }, - "250": { - "key": 150, - "doc_count": 0 - }, - "300": { - "key": 150, - "doc_count": 1 + "buckets": { + "0": { + "key": 0, + "doc_count": 2 + }, + "50": { + "key": 50, + "doc_count": 0 + }, + "150": { + "key": 150, + "doc_count": 3 + }, + "200": { + "key": 150, + "doc_count": 0 + }, + "250": { + "key": 150, + "doc_count": 0 + }, + "300": { + "key": 150, + "doc_count": 1 + } } } } @@ -242,19 +248,21 @@ Response: { "aggregations": { "prices": { - "0": { - "key": 0, - "doc_count": 2 - }, - "50": { - "key": 50, - "doc_count": 4 - }, - "150": { - "key": 150, - "doc_count": 3 + "buckets": { + "0": { + "key": 0, + "doc_count": 2 + }, + "50": { + "key": 50, + "doc_count": 4 + }, + "150": { + "key": 150, + "doc_count": 3 + } } } - } + } } -------------------------------------------------- diff --git a/docs/reference/search/aggregations/bucket/iprange-aggregation.asciidoc b/docs/reference/search/aggregations/bucket/iprange-aggregation.asciidoc index a76df06d78d..def09e6cd78 100644 --- a/docs/reference/search/aggregations/bucket/iprange-aggregation.asciidoc +++ b/docs/reference/search/aggregations/bucket/iprange-aggregation.asciidoc @@ -30,18 +30,20 @@ Response: ... "aggregations": { - "ip_ranges": [ - { - "to": 167772165, - "to_as_string": "10.0.0.5", - "doc_count": 4 - }, - { - "from": 167772165, - "from_as_string": "10.0.0.5", - "doc_count": 6 - } - ] + "ip_ranges": + "buckets" : [ + { + "to": 167772165, + "to_as_string": "10.0.0.5", + "doc_count": 4 + }, + { + "from": 167772165, + "from_as_string": "10.0.0.5", + "doc_count": 6 + } + ] + } } } -------------------------------------------------- @@ -71,24 +73,26 @@ Response: -------------------------------------------------- { "aggregations": { - "ip_ranges": [ - { - "key": "10.0.0.0/25", - "from": 1.6777216E+8, - "from_as_string": "10.0.0.0", - "to": 167772287, - "to_as_string": "10.0.0.127", - "doc_count": 127 - }, - { - "key": "10.0.0.127/25", - "from": 1.6777216E+8, - "from_as_string": "10.0.0.0", - "to": 167772287, - "to_as_string": "10.0.0.127", - "doc_count": 127 - } - ] + "ip_ranges": { + "buckets": [ + { + "key": "10.0.0.0/25", + "from": 1.6777216E+8, + "from_as_string": "10.0.0.0", + "to": 167772287, + "to_as_string": "10.0.0.127", + "doc_count": 127 + }, + { + "key": "10.0.0.127/25", + "from": 1.6777216E+8, + "from_as_string": "10.0.0.0", + "to": 167772287, + "to_as_string": "10.0.0.127", + "doc_count": 127 + } + ] + } } } -------------------------------------------------- \ No newline at end of file diff --git a/docs/reference/search/aggregations/bucket/range-aggregation.asciidoc b/docs/reference/search/aggregations/bucket/range-aggregation.asciidoc index fadb0f60289..41a4dd19035 100644 --- a/docs/reference/search/aggregations/bucket/range-aggregation.asciidoc +++ b/docs/reference/search/aggregations/bucket/range-aggregation.asciidoc @@ -31,21 +31,23 @@ Response: ... "aggregations": { - "price_ranges": [ - { - "to": 50, - "doc_count": 2 - }, - { - "from": 50, - "to": 100, - "doc_count": 4 - }, - { - "from": 100, - "doc_count": 4 - } - ] + "price_ranges" : { + "buckets": [ + { + "to": 50, + "doc_count": 2 + }, + { + "from": 50, + "to": 100, + "doc_count": 4 + }, + { + "from": 100, + "doc_count": 4 + } + ] + } } } -------------------------------------------------- @@ -81,19 +83,21 @@ Response: ... "aggregations": { - "price_ranges": { - "*-50.0": { - "to": 50, - "doc_count": 2 - }, - "50.0-100.0": { - "from": 50, - "to": 100, - "doc_count": 4 - }, - "100.0-*": { - "from": 100, - "doc_count": 4 + "price_ranges" : { + "buckets": { + "*-50.0": { + "to": 50, + "doc_count": 2 + }, + "50.0-100.0": { + "from": 50, + "to": 100, + "doc_count": 4 + }, + "100.0-*": { + "from": 100, + "doc_count": 4 + } } } } @@ -128,7 +132,7 @@ It is also possible to customize the key for each range: { "aggs" : { "price_ranges" : { - "range" : { + "range" : { "script" : "doc['price'].value", "ranges" : [ { "to" : 50 }, @@ -200,42 +204,44 @@ Response: -------------------------------------------------- { "aggregations": { - "price_ranges": [ - { - "to": 50, - "doc_count": 2, - "price_stats": { - "count": 2, - "min": 20, - "max": 47, - "avg": 33.5, - "sum": 67 + "price_ranges" : { + "buckets": [ + { + "to": 50, + "doc_count": 2, + "price_stats": { + "count": 2, + "min": 20, + "max": 47, + "avg": 33.5, + "sum": 67 + } + }, + { + "from": 50, + "to": 100, + "doc_count": 4, + "price_stats": { + "count": 4, + "min": 60, + "max": 98, + "avg": 82.5, + "sum": 330 + } + }, + { + "from": 100, + "doc_count": 4, + "price_stats": { + "count": 4, + "min": 134, + "max": 367, + "avg": 216, + "sum": 864 + } } - }, - { - "from": 50, - "to": 100, - "doc_count": 4, - "price_stats": { - "count": 4, - "min": 60, - "max": 98, - "avg": 82.5, - "sum": 330 - } - }, - { - "from": 100, - "doc_count": 4, - "price_stats": { - "count": 4, - "min": 134, - "max": 367, - "avg": 216, - "sum": 864 - } - } - ] + ] + } } } -------------------------------------------------- diff --git a/docs/reference/search/aggregations/bucket/terms-aggregation.asciidoc b/docs/reference/search/aggregations/bucket/terms-aggregation.asciidoc index 0cc3582030c..29326eaea6c 100644 --- a/docs/reference/search/aggregations/bucket/terms-aggregation.asciidoc +++ b/docs/reference/search/aggregations/bucket/terms-aggregation.asciidoc @@ -274,8 +274,8 @@ There are two mechanisms by which terms aggregations can be executed: either by data per-bucket (`map`), or by using ordinals of the field values instead of the values themselves (`ordinals`). Although the latter execution mode can be expected to be slightly faster, it is only available for use when the underlying data source exposes those terms ordinals. Moreover, it may actually be slower if most field values are unique. Elasticsearch tries to have sensible -defaults when it comes to the execution mode that should be used, but in case you know that an execution mode may perform better -than the other one, you have the ability to provide Elasticsearch with a hint: +defaults when it comes to the execution mode that should be used, but in case you know that one execution mode may perform better +than the other one, you have the ability to "hint" it to Elasticsearch: [source,js] -------------------------------------------------- diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogram.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogram.java index 995a9d887bc..1de1e5281a1 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogram.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogram.java @@ -363,10 +363,11 @@ public class InternalHistogram extends Inter @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(name); if (keyed) { - builder.startObject(name); + builder.startObject(CommonFields.BUCKETS); } else { - builder.startArray(name); + builder.startArray(CommonFields.BUCKETS); } for (B bucket : buckets) { @@ -396,7 +397,7 @@ public class InternalHistogram extends Inter } else { builder.endArray(); } - return builder; + return builder.endObject(); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java index 95a5f4d9051..9a7b1badef5 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalRange.java @@ -294,26 +294,27 @@ public class InternalRange extends InternalAggre out.writeDouble(((Bucket) bucket).from); out.writeDouble(((Bucket) bucket).to); out.writeVLong(((Bucket) bucket).docCount); - ((Bucket) bucket).aggregations.writeTo(out); + bucket.aggregations.writeTo(out); } } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(name); if (keyed) { - builder.startObject(name); + builder.startObject(CommonFields.BUCKETS); } else { - builder.startArray(name); + builder.startArray(CommonFields.BUCKETS); } for (B range : ranges) { - ((Bucket) range).toXContent(builder, params, formatter, keyed); + range.toXContent(builder, params, formatter, keyed); } if (keyed) { builder.endObject(); } else { builder.endArray(); } - return builder; + return builder.endObject(); } }