Ahh okay, Give this a try. <base_search>
| where ('_time'>=relative_time(_time, "@h-5m@m") AND '_time'<=relative_time(_time, "@h+5m@m")) OR ('_time'>=relative_time(_time, "+1h@h-5m@m") AND '...
See more...
Ahh okay, Give this a try. <base_search>
| where ('_time'>=relative_time(_time, "@h-5m@m") AND '_time'<=relative_time(_time, "@h+5m@m")) OR ('_time'>=relative_time(_time, "+1h@h-5m@m") AND '_time'<=relative_time(_time, "+1h@h+5m@m"))
| eval
upper_hour_epoch=relative_time(_time, "+1h@h"),
lower_hour_epoch=relative_time(_time, "@h"),
upper_hour=strftime(relative_time(_time, "+1h@h"), "%Y-%m-%d %H:%M:%S"),
lower_hour=strftime(relative_time(_time, "@h"), "%Y-%m-%d %H:%M:%S"),
upper_hour_diff=abs('_time'-'upper_hour_epoch'),
lower_hour_diff=abs('_time'-'lower_hour_epoch'),
diff_minimum=min(upper_hour_diff, lower_hour_diff)
| foreach *_diff
[
| eval
snap_hour=if(
'diff_minimum'=='<<FIELD>>',
'<<MATCHSTR>>',
'snap_hour'
)
]
| stats
count as count,
min(_time) as min_time,
max(_time) as max_time
by snap_hour
| convert
ctime(min_time),
ctime(max_time) The output should only include results +/- 5 minute window around each hour And if you need to differentiate between the event_counts that fall in the lower 5 minutes and upper 5 minutes you could do something like this. <base_search>
| where ('_time'>=relative_time(_time, "@h-5m@m") AND '_time'<=relative_time(_time, "@h+5m@m")) OR ('_time'>=relative_time(_time, "+1h@h-5m@m") AND '_time'<=relative_time(_time, "+1h@h+5m@m"))
| eval
upper_hour_epoch=relative_time(_time, "+1h@h"),
lower_hour_epoch=relative_time(_time, "@h"),
upper_hour=strftime(relative_time(_time, "+1h@h"), "%Y-%m-%d %H:%M:%S"),
lower_hour=strftime(relative_time(_time, "@h"), "%Y-%m-%d %H:%M:%S"),
upper_hour_diff=abs('_time'-'upper_hour_epoch'),
lower_hour_diff=abs('_time'-'lower_hour_epoch'),
diff_minimum=min(upper_hour_diff, lower_hour_diff)
| foreach *_diff
[
| eval
snap_hour=if(
'diff_minimum'=='<<FIELD>>',
'<<MATCHSTR>>',
'snap_hour'
)
]
| fields - diff_minimum, lower_hour, lower_hour_diff, lower_hour_epoch, upper_hour, upper_hour_diff, upper_hour_epoch
| eval
snap_hour_epoch=strptime(snap_hour, "%Y-%m-%d %H:%M:%S"),
group=if(
'_time'-'snap_hour_epoch'>=0,
"+5m",
"-5m"
)
| stats
count as count
by snap_hour_epoch, group
| sort 0 +snap_hour_epoch
| rename
snap_hour_epoch as _time Example output: