Help with aggregation needed


(Emil Mirzayev) #1

Hi there!

I have a dataset of different devices and their consumption values (absolute) which are increasing by the time.
Every device is connected to a group (there are 3 groups overall). What I want to achieve, is, to find the consumption of each group. It will be the sum of all latest values of the devices connected to that group.
I tried a query, but I failed to write the correct one:

POST measurements/_search
{
  "size": 0,
  "aggs": {
    "max_per_group": {
      "terms": {
        "field": "group_name",
        "size": 99999
      },
      "aggs": {
        "max_meter": {
          "terms": {
            "field": "meter_id"
          },
          "aggs": {
            "max_cons": {
              "max": {
                "field": "value"
              }
            }
          }
        },
        "max_per_group" :{
          "sum_bucket": {
            "buckets_path": "max_meter>max_cons"
          }
        }
      }
    }
  }
}

It gives me the output:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 96000,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "max_per_group": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "Erfurt-Zone1",
          "doc_count": 61440,
          "max_meter": {
            "doc_count_error_upper_bound": 981,
            "sum_other_doc_count": 55312,
            "buckets": [
              ........................
          },
          "max_per_group": {
            "value": 489.1849772365934
          }

Which is incorrect It should be around 3k, and the aggregation gives me just 10 meters for that group, despite 60~.
What am I doing wrong here? Can you help me with this query? Thanks!


(Zachary Tong) #2

I think the issue here is that you need to specify a size on the "max_meter" terms agg as well, otherwise it will only show you the top 10 meters by default.


(Emil Mirzayev) #3

Thanks! I have missed this tiny detail. Resolved


(system) #4

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