How to do arithmetic calculations on the results from an Average Bucket

i am calculating the sum of time with daily interval and using it with the average bucket to get the total overall average, now i want to divide that result by the total number of users. but i cant seem to be able to do that with the result of the average bucket.

{
  "size": 0,
  "aggs": {
    "sum_per_day": {
      "date_histogram": {
        "field": "@timestamp",
        "calendar_interval": "day"
      },
      "aggs": {
        "time": {
          "sum": {
            "field": "timeSpent"
          }
        }
      }
    },
    "overall_average": {
      "avg_bucket": {
        "buckets_path": "sum_per_day>time"
      }
    }
  },
    "script_fields": {
      "avg_per_user": {
        "script": "aggregations.overall_average.value/30"
      }
    }
  }

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