Show an Scripted Value in a Visualization

Hi,

I'm creating a dashboard and now I need to show the unitary value of the products, this value must be dynamical along the time, the unitary value must be calculated adding all the prices and adding all the units to divide later, I had created a query in Elasticsearch that calculate the thing that I need. The problem is I don't know how to show the result in Kibana

    {
      "size": 0,
      "query": {
        "range": {
          "@timestamp": {
            "gte": "2021-01-01",
            "lte": "2021-02-08"
          }
        }
      },
      "aggs": {
        "Prducts": {
          "terms": {
            "field": "reg_nr.keyword",
            "size": 10
          },
          "aggs": {
            "total_unit": {
              "sum": {
                "field": "pesoneto"
              }
            },
            "total_flete": {
              "sum": {
                "field": "fletetot"
              }
            },
            "UnitaryValue": {
              "bucket_script": {
                "buckets_path": {
                  "unit": "total_unit",
                  "total": "total_flete"
                },
                "script": {
                  "source": "(params.total / params.unit)"
                }
              }
            }
          }
        }
      }
    }
2 Likes

Hello,
Sadly the bucket script aggregation is not available in Kibana other visualizations:

But you can use it in TSVB, where it's been renamed to Math aggregation.

@Juan_Montoya You can use Vega visualizations in Kibana.

It'll allow you to write and visualize your own query.

It is flexible enough to meet your requirements.

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