I'm not sure of the proper approach for this query. I have a list of events,one event per day, with fields min,max and base. Starting with any date I need to pull the base for that date as well as the highest Max in a range span of 3 or 4 events [Note: I say events because because the log has missing dates].
as an Example snippet:
I would need to return the date, its base and the highest Max in the range:
Date, Base, Max
2014-07-18, 8.45, 8.68
For creating the ranges, should I should use a span or a bin with a foreach or is there a more appropriate method?
Not sure if I understand your requirements correctly... here's what I think you want:
grab the event for the specified date
grab the next (for example) 3 events that happened after that - might be the next three days, might have gaps
return the original event's date and base value as well as the maximum max value over all four events
Since there's no way or knowing how far in the future you need to look to get the next three events you could do something like this run over a timerange from the specified date to now:
your base search | tail 4 | stats earliest(Date) as Date earliest(Base) as Base max(Max) as Max
If your specified date is far into the past and there's a lot of data since then this would churn through all of the data and discard most of them - so if possible you can specify a latest time closer to the specified date but far away enough to be sure there will be another three events in there.