# Getting statistics for each bucket in the facet result

**URL:** <https://discuss.elastic.co/t/getting-statistics-for-each-bucket-in-the-facet-result/8623>\
**Category:** Elasticsearch\
**Created:** [August 3, 2012, 8:57am UTC](https://discuss.elastic.co/t/getting-statistics-for-each-bucket-in-the-facet-result/8623 "2012-08-03T08:57:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdd](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@jdd](https://discuss.elastic.co/u/jdd)\
**Post date:** [August 3, 2012, 8:57am UTC](https://discuss.elastic.co/t/getting-statistics-for-each-bucket-in-the-facet-result/8623/1 "2012-08-03T08:57:18Z")

</div>

Hi,  
I have a document with two fields, timestamp (date) and response\_time  
(numeric).  
Now suppose I want to do a query like 'Get the daily average response time  
for each day of the last 10 days', what's the recommended way to do this?  
If I want to use the Statistical facet, then I will have to fire the same  
query (changing date range in the filter each time) 10 times. Is there a  
way this could be done in a single query?

Basically I want to do a date range facet on the timestamp field, and for  
each daily bucket I want to calculate the statistical function (like mean,  
max, distinct etc)

Thanks,  
Jaideep

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [August 3, 2012, 4:51pm UTC](https://discuss.elastic.co/t/getting-statistics-for-each-bucket-in-the-facet-result/8623/2 "2012-08-03T16:51:05Z")

</div>

A Date Histogram Facet with the Value Field set is probably what you  
are looking for:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Cheers,

Ivan

On Fri, Aug 3, 2012 at 1:57 AM, jdd [jaideep.dhok@gmail.com](mailto:jaideep.dhok@gmail.com) wrote:

> Hi,  
> I have a document with two fields, timestamp (date) and response\_time  
> (numeric).  
> Now suppose I want to do a query like 'Get the daily average response time  
> for each day of the last 10 days', what's the recommended way to do this?  
> If I want to use the Statistical facet, then I will have to fire the same  
> query (changing date range in the filter each time) 10 times. Is there a way  
> this could be done in a single query?
> 
> Basically I want to do a date range facet on the timestamp field, and for  
> each daily bucket I want to calculate the statistical function (like mean,  
> max, distinct etc)
> 
> Thanks,  
> Jaideep

---

<div class="post-metadata">

**Author:** ![jdd](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@jdd](https://discuss.elastic.co/u/jdd)\
**Post date:** [August 3, 2012, 5:19pm UTC](https://discuss.elastic.co/t/getting-statistics-for-each-bucket-in-the-facet-result/8623/3 "2012-08-03T17:19:26Z")

</div>

## That helps. Thanks,

Jaideep

On Friday, 3 August 2012 22:21:05 UTC+5:30, Ivan Brusic wrote:

> A Date Histogram Facet with the Value Field set is probably what you  
> are looking for:
> 
> [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/date-histogram-facet.html)
> 
> Cheers,
> 
> Ivan
> 
> On Fri, Aug 3, 2012 at 1:57 AM, jdd [jaideep.dhok@gmail.com](mailto:jaideep.dhok@gmail.com) wrote:
> 
> > Hi,  
> > I have a document with two fields, timestamp (date) and response\_time  
> > (numeric).  
> > Now suppose I want to do a query like 'Get the daily average response  
> > time  
> > for each day of the last 10 days', what's the recommended way to do  
> > this?  
> > If I want to use the Statistical facet, then I will have to fire the  
> > same  
> > query (changing date range in the filter each time) 10 times. Is there a  
> > way  
> > this could be done in a single query?
> > 
> > Basically I want to do a date range facet on the timestamp field, and  
> > for  
> > each daily bucket I want to calculate the statistical function (like  
> > mean,  
> > max, distinct etc)
> > 
> > Thanks,  
> > Jaideep

---

<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 6, 2017, 3:17am UTC](https://discuss.elastic.co/t/getting-statistics-for-each-bucket-in-the-facet-result/8623/4 "2017-07-06T03:17:48Z")

</div>


