elasticsearch/elasticsearch — pull request #6465 by Mpdreamz (2014-06-11 13:38:52+00:00)
Title: [Aggregations] Added _meta construct to inject metadata

This PR 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.

thank you @martijnvg for the help reading the `byte[]` representation of _meta properly

- this PR also fixes the response format of the new `geo_bounds` aggregation to wrap the result in a fieldname property

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

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
}
},
```