Using sub-aggregation result in parent


(Frederes) #1

Hello,

Here is a sample request :

{
"query": {
    "term": {
        "campaign": "8"
    }
},
"size" : 0,
"aggs": {
    "days" : {
        "date_histogram" : {
            "field" : "day",
            "interval" : "day",
            "format": "yyyy-MM-dd",
            "min_doc_count" : 1
        },
        "aggs": {
            "total_screens" : { "sum" : { "field" : "nbScreen" } },>         
            "pods": {
                "terms": {
                    "field": "pod_name",
                    "size": 0
                },
                "aggs": {
                    "max_screens" : { "max" : { "field" : "nbScreen" } }
                }
            }
        }
    }
}

}

I would like in fact the sum of max(nbScreen) how can i do this ?
Is it possible to use the result of a sub-aggregation as the input field of another aggregation ? (parent one)


(Frederes) #2

I found the "stats_bucket" function that may help in my case, here is my query :

 {
    "query": {
        "term": {
            "campaign": "8"
        }
    },
    "size" : 0,
    "aggs": {
        "days" : {
            "date_histogram" : {
                "field" : "day",
                "interval" : "day",
                "format": "yyyy-MM-dd",
                "min_doc_count" : 1
            },
            "aggs": {
                "pods": {
                    "terms": {
                        "field": "pod_name",
                        "size": 0
                    },
                    "aggs": {
                        "max_screens" : { "max" : { "field" : "nbScreen" } }
                    }
                }
            }
        },
        "total_screens2": {
            "stats_bucket": {
                "buckets_path": "days>pods>max_screens"
            }
        }
    }
}

But i have an error on the "bukets_path" :

{
   "error": {
      "root_cause": [],
      "type": "reduce_search_phase_exception",
      "reason": "[reduce] ",
      "phase": "fetch",
      "grouped": true,
      "failed_shards": [],
      "caused_by": {
         "type": "aggregation_execution_exception",
         "reason": "buckets_path must reference either a number value or a single value numeric metric aggregation, got: java.lang.Object[]"
      }
   },
   "status": 503
}

How can i specify this : days>pods>max_screens ?


(system) #3