Bucket_script within Children aggregation


#1

Hello.
I would like to ask if it possible to run bucket script within children aggregation in a query.
Aggregation looks like this one.

"aggs": {
"summary": {
  "terms": {
    "field": "customerId",
    "size": 100000
  },
  "aggs": {
    "summary_per_children": {
      "children": {
        "type": "projects"
      },
      "aggs": {
        "Total_number_of_job_views": {
          "sum": {
            "field": "numberOfUsers"
          }
        },
        "Total_number_of_applications": {
          "sum": {
            "field": "numberOfApplicants"
          }
        },
        "Job views turning into an application": {
          "bucket_script": {
            "buckets_path": {
              "totalViews": "Total_number_of_job_views",
              "totalApplicants": "Total_number_of_applications"
            },
            "script": {
              "lang": "painless",
              "inline": "if (params.totalViews > 0) {params.totalApplicants / params.totalViews * 100} else {0}"
            }
          }
        }            
      }
    }
  }
}
  }

So now I get just this error below.

{
   "error": {
"root_cause": [],
"type": "reduce_search_phase_exception",
"reason": "[reduce] ",
"phase": "fetch",
"grouped": true,
"failed_shards": [],
"caused_by": {
  "type": "class_cast_exception",
  "reason": "org.elasticsearch.search.aggregations.bucket.children.InternalChildren cannot be cast to org.elasticsearch.search.aggregations.InternalMultiBucketAggregation"
}
  },
  "status": 503
}

OR this one if pathes are
"totalViews": "summary_per_children>Total_number_of_job_views",
"totalApplicants": "summary_per_children>Total_number_of_applications"

{
  "error": {
"root_cause": [
  {
    "type": "illegal_argument_exception",
    "reason": "No aggregation found for path [summary_per_children>Total_number_of_applications]"
  }
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
  {
    "shard": 0,
    "index": "",
    "node": "",
    "reason": {
      "type": "illegal_argument_exception",
      "reason": "No aggregation found for path [summary_per_children>Total_number_of_applications]"
    }
  }
],
"caused_by": {
  "type": "illegal_argument_exception",
  "reason": "No aggregation found for path [summary_per_children>Total_number_of_applications]"
}
  },
  "status": 400
}

(system) #2