# Global aggregations on nested documents

**URL:** <https://discuss.elastic.co/t/global-aggregations-on-nested-documents/153989>\
**Category:** Elasticsearch\
**Created:** [October 25, 2018, 11:18am UTC](https://discuss.elastic.co/t/global-aggregations-on-nested-documents/153989 "2018-10-25T11:18:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre-Loan\_Janczak](https://avatars.discourse-cdn.com/v4/letter/p/71e660/32.png) [@Pierre-Loan\_Janczak](https://discuss.elastic.co/u/Pierre-Loan_Janczak)\
**Post date:** [October 25, 2018, 11:18am UTC](https://discuss.elastic.co/t/global-aggregations-on-nested-documents/153989/1 "2018-10-25T11:18:41Z")

</div>

Hi,

I was wondering if it is possible to have a global aggregation based on a nested property within a document.

I stumbled upon this in the elastic documentation ☹[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html))

"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."

Does that mean that it is not possible ?

Thanks,  
Pierre

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [October 29, 2018, 11:41am UTC](https://discuss.elastic.co/t/global-aggregations-on-nested-documents/153989/3 "2018-10-29T11:41:19Z")

</div>

Can you give a bit more context of what you're trying to achieve? The global aggregation is just a way to "escape" the query context. E.g. a query may match a subset of the documents, which are then given to the aggregation for calculating metrics, etc.

The Global agg lets you run aggregations on _all_ the documents, whether they matched the query or not.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 26, 2018, 11:41am UTC](https://discuss.elastic.co/t/global-aggregations-on-nested-documents/153989/4 "2018-11-26T11:41:20Z")

</div>

Closed on November 26, 2018, 11:41am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
