I am trying to get time duration between each grouped field.
Example:
My document is shown below:
{
"timestamp":"2017-07-31T15:05:04.563Z",
"session_id":"1",
"user_id":"jenny"
}
I want to get time duration in each session_id.
Moreover, I got a reference of searching solution from stackoverflow(http://bit.ly/2vaBHHj) shown below:
{
"aggs": {
"group_by_uid": {
"terms": {
"field": "user_id"
},
"aggs": {
"group_by_sid": {
"terms": {
"field": "session_id"
},
"aggs": {
"session_start": {
"top_hits": {
"size": 1,
"sort": [ { "timestamp": { "order": "asc" } } ]
}
},
"session_end": {
"top_hits": {
"size": 1,
"sort": [ { "timestamp": { "order": "desc" } } ]
}
}
}
}
}
}
}
}
My question is that how can I get the time duration (session_end.timestamp - session_start.timestamp )?
Can anybody help me ? Thank you!