elasticsearch/elasticsearch — pull request #8279 by Mpdreamz (2014-10-29 21:07:14+00:00)
Title: [Aggregations] Meta data support

This commit adds the ability to associate a bit of state with each individual aggregation.

Use cases:
- Typed clients can inject some state so that the deserialization
process has enough information to deserialize the aggregations into
the correct type. Facets return `_type` to signal what kind of facet the
response corresponds with.
- UI state, since aggregations can be nested at arbitrary depths
injecting pieces of UI state can greatly simplify programming with
aggregations since there are no two tree data-structures to walk anymore only the aggregation data.

[Here's a gist of a sense session](https://gist.github.com/Mpdreamz/785a3347d4415e1fe6bb#file-aggs-metada) you can use to review this branch

This PR supersedes #6465 which got stale and horribly out of date with all the new aggregations in `1.2-1.4`.

Tested on a cluster of multiple nodes as well.

Example request:

```json
{
"aggs": {
"name": {
"terms": {
"field": "title"
},
"meta": 2,
"aggs": {
"viewport" : {
"meta" : {
"complex" : "object"
},
"geo_bounds" : {
"field" : "location"
}
},
"empty_agg" : {
"meta" : "should still be returned",
"sum": {
"field": "i_do_not_exist"
}
},
```

Example response:

```json
{
"aggregations": {
"name": {
"meta": 2,
"buckets": [
{
"key": "banner",
"doc_count": 1,
"viewport": {
"meta": {
"complex": "object"
},
"bounds": {
"top_left": {
"lat": 28,
"lon": 21
},
"bottom_right": {
"lat": 28,
"lon": 21
}
}
},
"nested_terms": {
"meta": {
"complex": "object",
"nuber": 1
},
"buckets": [
{
"key": "a",
"doc_count": 1,
"counter": {
"meta": 4.1,
"value": 40
}
},
```