Visualizing Weighted Average Aggregation in Kibana

I've read a lot of documentation regarding single-value weighted average aggregation in Kibana, but can't seem to find anything on the actual application of this in a dashboard or visualization. My knowledge of Kibana syntax is limited, therefore I rely mostly on the point-and-click functionality offered in Kibana's "Visualize" feature.

I am trying to visualize a bar chart that reflects the weighted average of a single field. I have the field that must be averaged as well as another field that contains the corresponding weights. Is it possible to create a weighted average aggregation using these fields and visualize this in a bar chart? Thanks!

Hi, we maintain a list of supported aggregations by visualization in Kibana: Supported features by panel type | Kibana Guide [7.12] | Elastic

Unfortunately, none of our point-and-click tools offer a weighted average. You can use Vega to create a single-metric chart, kind of like this:

{
  $schema: https://vega.github.io/schema/vega-lite/v4.json
  data: {
    url: {
      %context%: true
      %timefield%: timestamp
      index: kibana_sample_data_flights
      body: {
          aggs: {
            myagg: {
              weighted_avg: {
                value: {
                  field: grade
                }
                weight: {
                  field: weight
                }
              }
            }
          }
          // Speed up the response by only including aggregation results
          size: 0
        }
    }

    format: {property: "aggregations.myagg"}
  }

  mark: text

  encoding: {
    text: {
      field: "value"
      type: quantitative
      format: ".2"
    }
    size: { value: 48 }
  }
}

2 Likes

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