How to create sub aggregation for bucket_script pipeline aggregation using java api client

We are trying to create aggregation for bucket script and getting following error:
No aggregation found at path : totalEndTimeUtcAGGR
Below is the aggregation query
{
"aggregations": {
"successExecutionCountAGGR": {
"filters": {
"filters": [
{
"term": {
"automationStatus": {
"value": "SUCCESS"
}
}
}
]
}
},
"mostCommonExitPointAGGR": {
"terms": {
"field": "exitPoint",
"shard_size": 2147483647,
"size": 1
}
},
"totalEndTimeUtcAGGR": {
"sum": {
"field": "endTimeUtc",
"missing": 1668542073946
}
},
"executionCountAGGR": {
"value_count": {
"field": "fqAutomationName"
}
},
"uniqueUserCountAGGR": {
"cardinality": {
"field": "agentId"
}
},
"OUTER": {
"aggregations": {
"totalDurationAGGR": {
"bucket_script": {
"buckets_path": {
"totalStartTime": "totalStartTimeUtcAGGR",
"totalEndTime": "totalEndTimeUtcAGGR"
},
"script": {
"source": "params.totalEndTime - params.totalStartTime"
}
}
},
"avgDurationAGGR": {
"bucket_script": {
"buckets_path": {
"avgEndTime": "avgEndTimeUtcAGGR",
"avgStartTime": "avgStartTimeUtcAGGR"
},
"script": {
"source": "params.avgEndTime - params.avgStartTime"
}
}
}
},
"date_histogram": { "field":"endTimeUtc"}
},
"totalStartTimeUtcAGGR": {
"sum": {
"field": "startTimeUtc"
}
},
"mostCommonExitReasonCodeAGGR": {
"terms": {
"field": "exitReasonCode",
"shard_size": 2147483647,
"size": 1
}
},
"avgEndTimeUtcAGGR": {
"avg": {
"field": "endTimeUtc",
"missing": 1668542073946
}
},
"avgStartTimeUtcAGGR": {
"avg": {
"field": "startTimeUtc"
}
}
}
}