# Geo bounds aggregation as a sub aggregator?

**URL:** <https://discuss.elastic.co/t/geo-bounds-aggregation-as-a-sub-aggregator/18856>\
**Category:** Elasticsearch\
**Created:** [July 24, 2014, 6:46am UTC](https://discuss.elastic.co/t/geo-bounds-aggregation-as-a-sub-aggregator/18856 "2014-07-24T06:46:31Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 24, 2014, 9:05am UTC](https://discuss.elastic.co/t/geo-bounds-aggregation-as-a-sub-aggregator/18856/4 "2014-07-24T09:05:29Z")

</div>

I think the problem is that you have an extra aggregations object  
surrounding the geo\_bounds aggregation. Try the following:

curl -XGET "[http://localhost:9200/postings/\_search](http://localhost:9200/postings/_search)" -d'  
{  
"query": {  
"filtered": {  
"filter": {  
"geo\_bounding\_box": {  
"point": {  
"bottom\_right": [  
104.45856200712711,  
52.208730692828844  
],  
"top\_left": [  
104.19077025908017,  
52.34035674074375  
]  
}  
}  
},  
"query": {  
"match\_all": {}  
}  
}  
},  
"aggregations": {  
"cells": {  
"geohash\_grid": {  
"field": "point",  
"precision": 6  
},  
"aggregations": {  
"lat": {  
"avg": {  
"script": "doc["point"].lat"  
}  
},  
"lon": {  
"avg": {  
"script": "doc["point"].lon"  
}  
},  
"hits": {  
"top\_hits": {  
"\_source": {  
"include": [  
"short\_description"  
]  
},  
"size": 1  
}  
},  
"bounds": {  
"geo\_bounds": {  
"field": "point"  
}  
}  
}  
}  
},  
"size": 0  
}'

On Thursday, 24 July 2014 09:32:10 UTC+1, svartalf wrote:

> Here is an example: [request.sh · GitHub](https://gist.github.com/svartalf/c3cb76c40dd4fa1374fa)
> 
> I'm using two inner aggregation functions, and with "top\_hits" removed,  
> "geo\_bounds" works sometimes, and sometimes fails with a `response_2.json`  
> (in the example) or `response_3.json`.  
> With an enabled "top\_hits" aggregator it is also throwing  
> `response_1.json` text.
> 
> I'm trying to group points into the buckets and annotate them with a  
> top\_hit item and geo bounds for each bucket, and got stuck a little. Maybe  
> I should move one of those two aggregations one level deeper?
> 
> четверг, 24 июля 2014 г., 16:52:01 UTC+9 пользователь Colin  
> Goodheart-Smithe написал:
> 
> > You should be able to achieve this with the below query. If you still  
> > cannot get it working could you provide a cURL example which reproduces  
> > your issue?
> > 
> > curl -XGET "[http://localhost:9200/geo/\_search](http://localhost:9200/geo/_search)" -d'  
> > {  
> > "size": 0,  
> > "aggs": {  
> > "geohash" : {  
> > "geohash\_grid": {  
> > "field": "location",  
> > "precision": 3  
> > },  
> > "aggs": {  
> > "subbounds": {  
> > "geo\_bounds": {  
> > "field": "location"  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }'
> > 
> > On Thursday, 24 July 2014 07:46:31 UTC+1, svartalf wrote:
> > 
> > > Is there any way to use geo\_bounds as a sub aggregator?
> > > 
> > > I have a geohash\_grid aggregation, and it will be very useful to get  
> > > bounds for each bucket of the data.  
> > > Right now my ES 1.3.0 says that he "Could not find aggregator type  
> > > [bounds] in [aggregations]]".

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fd12bf52-9f3f-450c-a13d-547eef4fb926%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fd12bf52-9f3f-450c-a13d-547eef4fb926%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

_[View the full topic](https://discuss.elastic.co/t/geo-bounds-aggregation-as-a-sub-aggregator/18856)._
