# Is it possible to do a date histogram aggregation and get percent totals?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-do-a-date-histogram-aggregation-and-get-percent-totals/152143>\
**Category:** Elasticsearch\
**Created:** [October 12, 2018, 2:28am UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-date-histogram-aggregation-and-get-percent-totals/152143 "2018-10-12T02:28:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Baumgartner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jason_baumgartner/32/92716_2.png) [@Jason\_Baumgartner](https://discuss.elastic.co/u/Jason_Baumgartner)\
**Post date:** [October 12, 2018, 2:28am UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-date-histogram-aggregation-and-get-percent-totals/152143/1 "2018-10-12T02:28:23Z")

</div>

I have an Elasticsearch query that creates aggregations based on specific search terms. Within each bucket of the date histogram aggregation, the doc\_count gives the total number of documents matching the search criteria.

What I would also like is the total number of background documents for that time period so that I can do a ratio comparison. For instance, if my search term is "president" and the doc\_count in one of the buckets is 45,000, I'd like to get back the total number of documents for that time period as well.

I know this could be achieved by doing two separate aggregations, but I was curious if there was any built-in functionality to get the bg\_count for date histogram aggregations (all documents in that time range, not just matching documents).

Thank you!

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 15, 2018, 11:08am UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-date-histogram-aggregation-and-get-percent-totals/152143/2 "2018-10-15T11:08:27Z")

</div>

a second aggregation using the [global agg](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/search-aggregations-bucket-global-aggregation.html) sounds like the way to go here for me.

---

<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 12, 2018, 11:08am UTC](https://discuss.elastic.co/t/is-it-possible-to-do-a-date-histogram-aggregation-and-get-percent-totals/152143/3 "2018-11-12T11:08:30Z")

</div>

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