Another alternative: you can create a transform and visualize the ouput of it in kibana.
Transform supports scripted metric aggregations, see examples.
Transforms comes for the price of extra storage but reduces load at query time as you do not have to re-run aggregations which might be expensive.