Forgive my ignorance but could you provide a worked example of what you mean? I'm not getting exactly what you're after.
On 12 March 2014 13:24, Simon Cast <simon.c...@gmail.com> wrote: > Thanks Clinton. > > That looks interesting but that creates an average of values per hour for > the last 28 days. What I am looking for more precisely is to calculate a 28 > rolling (or moving average) using the last 28 days of data and redoing that > calculation every hour. > > I suppose what could be done is to do an average on a field that is a > hourly count. > > > > On Tuesday, March 11, 2014 11:35:40 AM UTC, Clinton Gormley wrote: > >> Yes, easily. Aggregations are really powerful. Here's an example: >> >> # First insert some data >> curl -XPUT "http://localhost:9200/myindex/mytype/1" -d' >> { >> "created": "2014/03/10 12:05:00", >> "somefield": 10 >> }' >> >> curl -XPUT "http://localhost:9200/myindex/mytype/2" -d' >> { >> "created": "2014/03/10 12:05:00", >> "somefield": 5 >> }' >> >> curl -XPUT "http://localhost:9200/myindex/mytype/3" -d' >> { >> "created": "2014/03/9 12:05:00", >> "somefield": 5 >> }' >> >> >> # Then return all results in the last 28 days >> # and calculate the avg per hour >> curl -XGET "http://localhost:9200/myindex/mytype/_search" -d' >> { >> "query": { >> "range": { >> "created": { >> "gte": "now-28d/d", >> "to": "now" >> } >> } >> }, >> "aggs": { >> "per_hour": { >> "date_histogram": { >> "field": "created", >> "interval": "hour" >> }, >> "aggs": { >> "rolling_avg": { >> "avg": { >> "field": "somefield" >> } >> } >> } >> } >> } >> }' >> >> >> >> On 11 March 2014 09:26, Simon Cast <simon...@gmail.com> wrote: >> >>> Hi, >>> >>> I'm looking at using the new aggregations module of Elasticsearch to >>> produce some metrics for my application. >>> >>> I want to calculate the rolling average for every hour in the last 28 >>> days and then plot these on a chart. I can see how this could be done using >>> a query per hour for the last 28 days. This seems problematic in terms of >>> load and performance. Can this be done using a single query? >>> >>> Regards, >>> >>> Simon >>> >>> >>> -- >>> 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. >>> >>> To view this discussion on the web visit https://groups.google.com/d/ >>> msgid/elasticsearch/d0a2dba7-f5a5-4944-ae0e-c6771b43ad6c% >>> 40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/d0a2dba7-f5a5-4944-ae0e-c6771b43ad6c%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elasticsearch/15324eca-2048-4a57-abe4-f1730e1bf70e%40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/15324eca-2048-4a57-abe4-f1730e1bf70e%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAPt3XKRFsY_F-dJdp2vN_yLOtHZ1-brdE%2BvxN7ATdapf4rnOow%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.