Hello,
Below is a sample trip document:
{
"vehicle" : "WB1234",
"startTime" : "2017-11-10T10:00:00",
"endTime" : "2017-11-10T21:00:00",
"distance" : 10,
}
{
"vehicle" : "WB1234",
"startTime" : "2017-11-10T12:00:00",
"endTime" : "2017-11-10T23:00:00",
"distance" : 20,
}
{
"vehicle" : "WB1235",
"startTime" : "2017-11-10T12:00:00",
"endTime" : "2017-11-10T23:00:00",
"distance" : 20,
}
Index contains multiple trip documents for each vehicle for a given day and there are many vehicles. We want to show avg distance travelled by all vehicles for a given date range.
- Get the total distance travelled by each vehicle across all trips
- Then show the Avg distance travelled by Vehicle
In terms of Elastic search Query for the same, we tried below query and its working fine.
{
"size":0,
"aggregations":{
"recent_trips":{
"filter":{
"range":{
"actualEndTime":{
"from":"2017-11-10T00:00:00.000Z",
"to":"2017-11-10T23:59:59.000Z",
"include_lower":true,
"include_upper":true
}
}
},
"aggregations":{
"by_vehicle":{
"terms":{
"field":"vehicleId.keyword"
},
"aggregations":{
"sum_travel_distance":{
"sum":{
"field":"distance"
}
}
}
},
"avg_distance": {
"avg_bucket" : {
"buckets_path" : "by_vehicle>sum_travel_distance"
}
}
}
}
}
}
How is it possible to display the avg_distance using 42 Metric visualization in Kibana ? Appreciate your help.