# Is there a way to efficiently get three layer aggrigations result in elasticsearch, where each layer is conditioned by above one

**URL:** https://discuss.elastic.co/t/is-there-a-way-to-efficiently-get-three-layer-aggrigations-result-in-elasticsearch-where-each-layer-is-conditioned-by-above-one/307788
**Category:** Elasticsearch
**Created:** [June 21, 2022, 5:35pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-efficiently-get-three-layer-aggrigations-result-in-elasticsearch-where-each-layer-is-conditioned-by-above-one/307788 "2022-06-21T17:35:41Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Robin\_Rawat](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robin_rawat/32/107372_2.png) [@Robin\_Rawat](https://discuss.elastic.co/u/Robin_Rawat)
#### Post date: [June 21, 2022, 5:35pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-efficiently-get-three-layer-aggrigations-result-in-elasticsearch-where-each-layer-is-conditioned-by-above-one/307788/1 "2022-06-21T17:35:41Z")

</div>

I am trying to get composite aggregation for certain feilds which are present in each document. These documents are stored in elastic. Format of each document is a json with below mentioned keys. **{"id","name","topic","bucket","key"}**

Now I want to get result in below format: **From documents, how much each topic count is, how much each bucket count is for each topic and how much key count is for each bucket.** Now I had thought of using three layer aggrigation query, but is real slow for api's. Could anyone suggest some better options.

---

<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: [July 19, 2022, 5:36pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-efficiently-get-three-layer-aggrigations-result-in-elasticsearch-where-each-layer-is-conditioned-by-above-one/307788/2 "2022-07-19T17:36:22Z")

</div>

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