Weighted Average in a DataTable of Kibana

Hi Henrique, I think solving your problem will be a two-step process.

  1. You'll need to create a per-document field for cost * volume, e.g. a field called volumeCost. You could create this field two ways, either by reindexing your data and adding the field with a Painless script, or by creating a scripted field that calculates this value on the fly. The first option is a little more performant when querying your data but the second option might be easier.

  2. I think you can create a Timeseries visualization in the Visualize app to generate the table you want. In the screenshot below, imagine the first aggregation for products.base_price is actually a reference to the volumeCost field and the second aggregation for products.quantity is actually a reference to the volume field. This way you can define a bucket script that performs the calculation you want, and order the results by product ID or name in a table.