Média da somatória de field

Alguém poderia compartilhar como aplicar uma divisão acumulada sobre a soma de fields?

Exemplo:

image

Ou seja, sempre preciso somar para depois dividir.

Grato,
Edmar

I don't speak Portuguese (sorry)! But maybe you can use Google translate as I did to understand your question?

Basically, you can use a pipeline aggregator:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html

They're available in Kibana in the Time Series Visual Builder. Here's an example of how you can do it directly (in the Kibana Dev Tools console, for example):

PUT myjobs/docs/1
{
  "field1": 44,
  "field2": 5
}

PUT myjobs/docs/2
{
  "field1": 22,
  "field2": 4
}

GET myjobs/_search
{
  "size": 0,
  "aggs": {
    "inelegant": {
      "terms": {
        "script": "'anything'"
      },
      "aggs": {
        "sum_field1": {
          "sum": {
            "field": "field1"
          }
        },
        "sum_field2": {
          "sum": {
            "field": "field2"
          }
        },
        "div_secs": {
          "bucket_script": {
            "buckets_path": {
              "sum_field1": "sum_field1",
              "sum_field2": "sum_field2"
            },
            "script": "params.sum_field1 / params.sum_field2"
          }
        }
      }
    }
  }
}

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