I am trying to determine the meantime between records, per month, for a set of documents. All documents have a timestamp, and I want to capture the average time between the timestamps on a monthly basis. Have tried several trial and error approaches, but nothing is giving me exactly what I want.
Doc 1:
{
"_index": "my_index",
"_type": "CO",
"_source": {
"timestamp": "2018-01-02T14:00:00",
"segment": "none",
"category": "Normal",
"plannedStart": "2018-01-02T14:00:00",
"subCategory": "Normal"
}
}
Doc 2:
{
"_index": "my_index",
"_type": "CO",
"_source": {
"timestamp": "2018-01-05T14:00:00",
"segment": "none",
"category": "Normal",
"plannedStart": "2018-01-05T14:00:00",
"subCategory": "Normal"
}
}
serial_diff seems to get me the closest to getting the deltas between the docs, but how to take the next step to aggregate the average of the deltas?
"aggs": {
"2": {
"date_histogram": {
"field": "timestamp",
"interval": "day",
"time_zone": "America/New_York",
"min_doc_count": 1
},
"aggs": {
"start": {
"sum":{
"field": "timestamp"
}
},
"delta": {
"serial_diff":{
"buckets_path":"start",
"lag": 1
}
}
}
}
}