How to plot speed derived from time and distance using aggregation

Hi,

I have an query that calculates average speed for different car makes based on the fields 'distance' and 'time' in travel documents in Elasticsearch:

POST /test_data/_search
{
	"size": 0,
	"aggs": {
		"speed_per_make": {
			"terms": {
				"field": "CarMake"
			},
			"aggs": {
				"sum_dist": {
					"sum": {
						"field": "DistanceCovered"
					}
				},
				"sum_time": {
					"sum": {
						"field": "DrivingDurationHours"
					}
				},
				"division": {
					"bucket_script": {
						"buckets_path": {
							"var_sum_dist": "sum_dist",
							"var_sum_time": "sum_time"
						},
						"script": "params.var_dist / params.var_time"
					}
				}
			}
		}
	}
}

For each car make it sums the distance and time, and then calculates the speed.
How can I plot this in a vertical bar chart?

Thanks!

Kibana core visualizations do not yet support bucket script aggregations, however you should be able to visualize this in TSVB if you are okay using a line chart instead of a bar chart.

Edit: adding a screengrab for clarity

Thanks for the quick reply!

I got it working by using vega. I can now display the average speed as a bar chart.

I will try TSVB too.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.