# How to create sub aggregation for bucket\_script pipeline aggregation using java api client

**URL:** <https://discuss.elastic.co/t/how-to-create-sub-aggregation-for-bucket-script-pipeline-aggregation-using-java-api-client/318999>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [November 15, 2022, 8:40pm UTC](https://discuss.elastic.co/t/how-to-create-sub-aggregation-for-bucket-script-pipeline-aggregation-using-java-api-client/318999 "2022-11-15T20:40:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raghunandan](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@Raghunandan](https://discuss.elastic.co/u/Raghunandan)\
**Post date:** [November 15, 2022, 8:40pm UTC](https://discuss.elastic.co/t/how-to-create-sub-aggregation-for-bucket-script-pipeline-aggregation-using-java-api-client/318999/1 "2022-11-15T20:40:33Z")

</div>

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"  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 13, 2022, 8:40pm UTC](https://discuss.elastic.co/t/how-to-create-sub-aggregation-for-bucket-script-pipeline-aggregation-using-java-api-client/318999/2 "2022-12-13T20:40:56Z")

</div>

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