# Aggregations across values returned by term then date histogram

**URL:** https://discuss.elastic.co/t/aggregations-across-values-returned-by-term-then-date-histogram/19739
**Category:** Elasticsearch
**Created:** [September 11, 2014, 6:08pm UTC](https://discuss.elastic.co/t/aggregations-across-values-returned-by-term-then-date-histogram/19739 "2014-09-11T18:08:52Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)
#### Post date: [September 11, 2014, 6:08pm UTC](https://discuss.elastic.co/t/aggregations-across-values-returned-by-term-then-date-histogram/19739/1 "2014-09-11T18:08:52Z")

</div>

I haven't been able to figure out how to do this and it may not be  
possible, but figured I'd ask.

I have a query with multiple aggregations that looks like this:

> <https://gist.github.com/ppearcy/0c6a86ebf32a0bbcb1fc>

This returns a time series of data per user:

> <https://gist.github.com/ppearcy/7ceac858da2e647ff341>

I want to do a stats aggregation across all the values for each week to  
provided per weekly statistical view of things.

Currently, I am doing these computations client side and it works pretty  
well, but have performance concerns around merging lots of time series  
streams.

Any help or ideas would be much appreciated.

Thanks!  
Paul

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a83cc20d-8c9c-4a6b-b843-349a2669e580%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a83cc20d-8c9c-4a6b-b843-349a2669e580%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)
#### Post date: [September 12, 2014, 12:31am UTC](https://discuss.elastic.co/t/aggregations-across-values-returned-by-term-then-date-histogram/19739/2 "2014-09-12T00:31:20Z")

</div>

Hello ,

I didn't get your question completely , but then i feel a simple date  
histogram query should do the trick.

"aggs" : {

```
    "{{time_interval}}": {
      "date_histogram": {
        "field": "time",
        "interval": "{{time_interval}}",
        "min_doc_count": 0
      }
    }
  }

```

Let me know if this doesn't fit your need and if so , what other data  
you are looking for .

Thanks  
Vineeth

On Thu, Sep 11, 2014 at 11:38 PM, ppearcy [ppearcy@gmail.com](mailto:ppearcy@gmail.com) wrote:

> I haven't been able to figure out how to do this and it may not be  
> possible, but figured I'd ask.
> 
> I have a query with multiple aggregations that looks like this:  
> [gist:0c6a86ebf32a0bbcb1fc · GitHub](https://gist.github.com/ppearcy/0c6a86ebf32a0bbcb1fc)
> 
> This returns a time series of data per user:  
> [gist:7ceac858da2e647ff341 · GitHub](https://gist.github.com/ppearcy/7ceac858da2e647ff341)
> 
> I want to do a stats aggregation across all the values for each week to  
> provided per weekly statistical view of things.
> 
> Currently, I am doing these computations client side and it works pretty  
> well, but have performance concerns around merging lots of time series  
> streams.
> 
> Any help or ideas would be much appreciated.
> 
> Thanks!  
> Paul
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/a83cc20d-8c9c-4a6b-b843-349a2669e580%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a83cc20d-8c9c-4a6b-b843-349a2669e580%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/a83cc20d-8c9c-4a6b-b843-349a2669e580%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/a83cc20d-8c9c-4a6b-b843-349a2669e580%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nZXHThM-odXc96kLmFTUa869qJkodQZpd%2Bw7NTWhJMeQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nZXHThM-odXc96kLmFTUa869qJkodQZpd%2Bw7NTWhJMeQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)
#### Post date: [September 12, 2014, 3:57am UTC](https://discuss.elastic.co/t/aggregations-across-values-returned-by-term-then-date-histogram/19739/3 "2014-09-12T03:57:47Z")

</div>

Hi,  
I am doing a terms aggregation on user with a sub date histogram  
aggregation to get time series per user. I then want to perform a stats  
aggregation all the values of each date bucket across users.

Thanks,  
Paul

On Thursday, September 11, 2014 8:32:13 PM UTC-4, vineeth mohan wrote:

> Hello ,
> 
> I didn't get your question completely , but then i feel a simple date  
> histogram query should do the trick.
> 
> "aggs" : {
> 
> ```
> "{{time_interval}}": {
> "date_histogram": {
> "field": "time",
> "interval": "{{time_interval}}",
> "min_doc_count": 0
> }
> }
> }
> 
> ```
> 
> Let me know if this doesn't fit your need and if so , what other data you are looking for .
> 
> Thanks  
> Vineeth
> 
> On Thu, Sep 11, 2014 at 11:38 PM, ppearcy \<[ppe...@gmail.com](mailto:ppe...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > I haven't been able to figure out how to do this and it may not be  
> > possible, but figured I'd ask.
> > 
> > I have a query with multiple aggregations that looks like this:  
> > [gist:0c6a86ebf32a0bbcb1fc · GitHub](https://gist.github.com/ppearcy/0c6a86ebf32a0bbcb1fc)
> > 
> > This returns a time series of data per user:  
> > [gist:7ceac858da2e647ff341 · GitHub](https://gist.github.com/ppearcy/7ceac858da2e647ff341)
> > 
> > I want to do a stats aggregation across all the values for each week to  
> > provided per weekly statistical view of things.
> > 
> > Currently, I am doing these computations client side and it works pretty  
> > well, but have performance concerns around merging lots of time series  
> > streams.
> > 
> > Any help or ideas would be much appreciated.
> > 
> > Thanks!  
> > Paul
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/a83cc20d-8c9c-4a6b-b843-349a2669e580%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a83cc20d-8c9c-4a6b-b843-349a2669e580%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/a83cc20d-8c9c-4a6b-b843-349a2669e580%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/a83cc20d-8c9c-4a6b-b843-349a2669e580%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3b0a967b-8445-4401-82fe-ee22c942d050%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3b0a967b-8445-4401-82fe-ee22c942d050%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:02am UTC](https://discuss.elastic.co/t/aggregations-across-values-returned-by-term-then-date-histogram/19739/4 "2017-07-06T01:02:55Z")

</div>


