OK, Binh took me aside and explained what you are after: a number per hour
which reflects the average of the previous 28*24 hours.

There are two ways you can do this with aggregations.  The first way is to
create overlapping buckets, so each date will fall into multiple windows,
eg:

    Jan 1, 10 am to Jan 28, 10am
    Jan 1, 11 am to Jan 28, 11am
    Jan 1, 12 am to Jan 28, 12am
    etc

... which can be done by constructing all of the date ranges you need, ie
28 * 24 of them.

The second way to do it is to use a script to convert each date into
multiple dates:
    $date
    $date - 1h
    $date - 2h
    $date - 3h
    ...
    $date - 672h

I've put together a simplified example (rolling avg per day) which
demonstrates both techniques.  Unfortunately, the script version showed up
a bug in aggregations, which will be fixed in 1.1.0 - currently you can
include 4 values, but no more.

See the demo here: https://gist.github.com/clintongormley/9515005

clint




On 12 March 2014 16:29, Clinton Gormley <cl...@traveljury.com> wrote:

> Heya Bihn
>
> The part I'm not getting is this: "the rolling average for every hour in
> the last 28 days". ie what period should each bucket/rolling avg cover?
> an hour? 28 days?
>
> You can still do rolling averages with aggregations, but they require a
> bit more work. I wanted to get the exact specs before trying to answer
> again :)
>
> clint
>
>
>
> On 12 March 2014 16:09, Binh Ly <binhly...@yahoo.com> wrote:
>
>> Unfortunately a MA aggregation is not available at the moment (unless you
>> accumulate/include all the prior data that you need into every doc, or you
>> run multiple queries and aggregate it yourself - neither of which is
>> desirable or flexible)
>>
>> Clint, a MA is an average computed in a "sliding window" fashion, where
>> the time interval slides as the average is computed. So for example, let's
>> say I have a daily statistic for 5 days:
>>
>> [Day1 = 100, Day 2 = 105, Day 3 = 101, Day 4 = 120, Day 5 = 200]
>>
>> A 2 day in-the-past MA would be computed as follows:
>>
>> Day1 = No data yet (since we don't have 2 days in-the-past worth of info)
>> Day2 = (Day1 + Day2) / 2 = (100 + 105) / 2
>> Day3 = (Day2 + Day3) / 2 = (105 + 101) / 2
>> ...
>>
>>
>>
>>
>>  --
>> 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/89d909af-377e-44bd-8cec-31249f9f1d60%40googlegroups.com<https://groups.google.com/d/msgid/elasticsearch/89d909af-377e-44bd-8cec-31249f9f1d60%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/CAPt3XKQ3ZGG9Ak4AWUgsk%3DYMkQez9%3DLWdixzosRbDQS5ouqUiQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to