How to write an ES query to find the difference between the maximum and minimum field value?
I am new to elasticity search. In my case I spend a lot of events along with session_id and time searching for elasticity. My event structure
Event_name string `json:"Event_name"`
Client_id string `json:"Client_id"`
App_id string `json:"App_id"`
Session_id string `json:"Session_id"`
User_id string `json:"User_id"`
Ip_address string `json:"Ip_address"`
Latitude int64 `json:"Latitude"`
Longitude int64 `json:"Longitude"`
Event_time time.Time `json:"Time"`
I want to find the session_id lifetime based on the events that were sent. To do this, I can get the maximum Event_time event and the minimum Event_time event for a specific session_id at the following ES request.
{
"size": 0,
"query": {
"match": {
"Session_id": "dummySessionId"
}
},
"aggs": {
"max_time": {
"max": {
"field": "Time"
}
},
"min_time":{
"min": {
"field": "Time"
}
}
}
}
But I want it for sure (max_time - min_time) How to write an ES request for the same ????
source
share