Calculate with Kibana metrics

I'm working in Kibana. I have an index with each document representing a sold product with product_quantity, order_id, customer_id, order_date and returned_quantity. I want to calculate a few things:

  1. Average number of orders per customer. Which means I have to calculate unique count of order_id / unique count of customer_id.

  2. Return rate. Which means I have to calculate sum of returned_quantity / sum of product_quantity to divide the number of all returned products by the number of all sold products.

In both cases I am only able to display the single metrics I need (like sum/ unique count) but I am not able to divide them by one another. I read that scripted fields could help but I don't think they can solve those cases plus I do not know how to write those scripts since I have no programming knowledge. Is there any way to do this?

This is not yet supported. This would be accomplished by using a bucket script aggregation. Please comment on this issue, https://github.com/elastic/kibana/issues/67405, to describe your use case and how you would like to configure the bucket script aggregation for your calculations.

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