# Elasticsearch Composite Aggregation Orderby in Java Client 8.8.2

**URL:** https://discuss.elastic.co/t/elasticsearch-composite-aggregation-orderby-in-java-client-8-8-2/360315
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [May 27, 2024, 5:36pm UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregation-orderby-in-java-client-8-8-2/360315 "2024-05-27T17:36:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tcpeiris](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@tcpeiris](https://discuss.elastic.co/u/tcpeiris)
#### Post date: [May 27, 2024, 5:36pm UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregation-orderby-in-java-client-8-8-2/360315/1 "2024-05-27T17:36:12Z")

</div>

I'm getting a parse exception when I add order to CompositeAggregationSource.

```auto
List<Map<String, CompositeAggregationSource>> casList = new ArrayList<>();

for (int i = 0; i < groupBy.size(); i++) {
  Map<String, CompositeAggregationSource> cas = new HashMap<>();
  String key = groupBy.get(i);

  List<NamedValue<SortOrder>> orderby = new ArrayList<>();
  sortingList.stream().forEach(sortingDto -> {
    if (sortingDto.getOrderBy().equals("ASC")) {
      orderby.add(NamedValue.of(key, SortOrder.Asc));
    } else {
      orderby.add(NamedValue.of(key, SortOrder.Desc));
    }

    cas.put(key,
        CompositeAggregationSource.of(
            c -> c.terms(t -> t.field(key).order(orderby))));
  });

  casList.add(i, cas);
}

```

I'm getting the following exception

```auto
"[es/search] failed: [x_content_parse_exception] [1:445] [composite] failed to parse field [sources]"

```

---

<div class="post-metadata">

### Author: ![ltrotta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltrotta/32/124003_2.png) [@ltrotta](https://discuss.elastic.co/u/ltrotta)
#### Post date: [May 27, 2024, 5:47pm UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregation-orderby-in-java-client-8-8-2/360315/2 "2024-05-27T17:47:47Z")

</div>

Hello! This was a bug we had involving the `order` field that was fixed in most recent versions, updating the java client should solve this.

---

<div class="post-metadata">

### Author: ![tcpeiris](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@tcpeiris](https://discuss.elastic.co/u/tcpeiris)
#### Post date: [May 28, 2024, 2:15am UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregation-orderby-in-java-client-8-8-2/360315/3 "2024-05-28T02:15:40Z")

</div>

Thank you
