# Conditionally run aggregation

**URL:** <https://discuss.elastic.co/t/conditionally-run-aggregation/269546>\
**Category:** Elasticsearch\
**Created:** [April 8, 2021, 5:04am UTC](https://discuss.elastic.co/t/conditionally-run-aggregation/269546 "2021-04-08T05:04:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhimawan](https://avatars.discourse-cdn.com/v4/letter/b/54ee81/32.png) [@bhimawan](https://discuss.elastic.co/u/bhimawan)\
**Post date:** [April 8, 2021, 5:04am UTC](https://discuss.elastic.co/t/conditionally-run-aggregation/269546/1 "2021-04-08T05:04:26Z")

</div>

I'm wondering if there's any way to run aggregation conditionally.  
So I have a \_search request that have both query and aggs param. So the aggs is scoped by the query param.

Now if the query return no hits, is there a way to skip the aggregation completely?

Thanks

---

<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:** [May 6, 2021, 5:04am UTC](https://discuss.elastic.co/t/conditionally-run-aggregation/269546/2 "2021-05-06T05:04:57Z")

</div>

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