Average aggregation across all available fields

Hello,

I was wondering if anyone knows how to perform average aggregations across all fields available in a record.

I have a setup where I have sensors, and I would like to take the average values of each field, without specifying each individual field.

Right now, this is what my query looks like:

{
  "size": 0,
  "query": {
    "range" : {
        "datetime" : {
            "gte": "2017-07-05T00:00:00", 
            "lte": "now" 
        }
    }
  },
  "aggs": {
    "dates": {
      "date_histogram": {
        "field": "datetime",
        "interval": "4h"
      },
      "aggs": {
        "sensors": {
          "terms": {
            "field": "sensorInfo.location.keyword",
            "size": 1000
          }
        }
      }
    }
  }
}

It first selects a range of data, then splits that range into specific time intervals (4 hours). From there, I split each time interval into the different sensors that I have.

E.g. In 4:00pm bucket, I have sensor 1, sensor 2 and sensor 3.

Although I can simply add an average aggregation within the sensor aggregation, I would have to specify each field manually.

...
"aggs": {
  "sensors": {
    "terms": {
      "field": "sensorInfo.location.keyword",
      "size": 1000
    },
    "aggs": {
      "avg_temp": {
        "avg": {
          "field": "temperature"
        }
      },
      "avg_rh": {
        "avg": {
          "field": "humidity"
        }
      },
      ...
    }
  }
}
...

Is there any way that I am able to have an average of each field in sensor taken, without the need of specifying each one?

Thanks!

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