# How to do Composite Aggregation with Multiple Term Aggregation in new Java Client

**URL:** <https://discuss.elastic.co/t/how-to-do-composite-aggregation-with-multiple-term-aggregation-in-new-java-client/332696>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [May 6, 2023, 6:56am UTC](https://discuss.elastic.co/t/how-to-do-composite-aggregation-with-multiple-term-aggregation-in-new-java-client/332696 "2023-05-06T06:56:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![varun1992](https://avatars.discourse-cdn.com/v4/letter/v/3da27b/32.png) [@varun1992](https://discuss.elastic.co/u/varun1992)\
**Post date:** [May 6, 2023, 6:56am UTC](https://discuss.elastic.co/t/how-to-do-composite-aggregation-with-multiple-term-aggregation-in-new-java-client/332696/1 "2023-05-06T06:56:05Z")

</div>

I am getting error when giving multiple term aggregation in composite aggregation sources

`[es/search] failed: [x_content_parse_exception] [1:177] [composite] failed to parse field [sources]`

my code as below

```auto
            Map<String, CompositeAggregationSource> map = new HashMap<>();

            map.put("Term1",
                    new CompositeAggregationSource.Builder().terms(d->d
                            .order(NamedValue.of("_key",SortOrder.Asc))
                            .field("agent.name")
                    ).build()
            );
            
            map.put("Term2",
                    new CompositeAggregationSource.Builder().terms(d->d
                            .order(NamedValue.of("_key",SortOrder.Asc))
                            .field("agent.type")
                    ).build()
            );
            
            List<Map<String, CompositeAggregationSource>> list = new ArrayList<>();
            list.add(map);

            SearchResponse<Void> response = client.search(b -> b
                            .index("*winlogbeat*")
                            .size(0)
                            .aggregations("name", t->t
                                    .composite(t1->t1
                                            .sources(map)))
                    ,
                    Void.class
            );

```

How to give multiple Term Aggregation in composite Aggregation ?

---

<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:** [June 3, 2023, 6:56am UTC](https://discuss.elastic.co/t/how-to-do-composite-aggregation-with-multiple-term-aggregation-in-new-java-client/332696/2 "2023-06-03T06:56:17Z")

</div>

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