# ElasticsearchClient issue: What is the new equivalent of the old AbstractAggregationBuilder's subAggregation method

**URL:** <https://discuss.elastic.co/t/elasticsearchclient-issue-what-is-the-new-equivalent-of-the-old-abstractaggregationbuilders-subaggregation-method/314228>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [September 12, 2022, 8:13pm UTC](https://discuss.elastic.co/t/elasticsearchclient-issue-what-is-the-new-equivalent-of-the-old-abstractaggregationbuilders-subaggregation-method/314228 "2022-09-12T20:13:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rudy\_Bonefas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rudy_bonefas/32/77328_2.png) [@Rudy\_Bonefas](https://discuss.elastic.co/u/Rudy_Bonefas)\
**Post date:** [September 12, 2022, 8:13pm UTC](https://discuss.elastic.co/t/elasticsearchclient-issue-what-is-the-new-equivalent-of-the-old-abstractaggregationbuilders-subaggregation-method/314228/1 "2022-09-12T20:13:42Z")

</div>

I have inherited some old RestHighLevelClient code (7.16.3) which I wish to upgrade to the new ElasticsearchClient. I am stumped on how to upgrade the following code:

```auto
AggregationBuilder ab = AggregationBuilders.composite("rootAggregation", valuesSourceBuilders);
ab.subAggregation(AggregationBuilders.stats('statsAggregation').field('time'));

```

My problem is how to turn the above into the new Builder based pattern. Please don't respond with a DSL example, I want to use the Builders directly for now

Thank youy

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [September 12, 2022, 8:51pm UTC](https://discuss.elastic.co/t/elasticsearchclient-issue-what-is-the-new-equivalent-of-the-old-abstractaggregationbuilders-subaggregation-method/314228/2 "2022-09-12T20:51:08Z")

</div>

Hi @Rudy_Bonefas  
Maybe this [post](https://discuss.elastic.co/t/sub-aggregations-in-java-api-client/312072/2) help you.

---

<div class="post-metadata">

**Author:** ![Rudy\_Bonefas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rudy_bonefas/32/77328_2.png) [@Rudy\_Bonefas](https://discuss.elastic.co/u/Rudy_Bonefas)\
**Post date:** [September 13, 2022, 1:23pm UTC](https://discuss.elastic.co/t/elasticsearchclient-issue-what-is-the-new-equivalent-of-the-old-abstractaggregationbuilders-subaggregation-method/314228/3 "2022-09-13T13:23:49Z")

</div>

Thats a start. The documentation for the old StatsAggregrationBuilder states that

`The stats that are returned consist of: `min`,`max`,`sum`,`count`and`avg` .`

So given the example you pointed to me, I now have to create 5 sub-aggregations instead of just 1?

Love the new API

---

<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:** [October 11, 2022, 1:24pm UTC](https://discuss.elastic.co/t/elasticsearchclient-issue-what-is-the-new-equivalent-of-the-old-abstractaggregationbuilders-subaggregation-method/314228/4 "2022-10-11T13:24:06Z")

</div>

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