# 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/340514
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [August 10, 2023, 7:17am UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregation-orderby-in-java-client-8-8-2/340514 "2023-08-10T07:17:16Z")
**Posts on this page:** 7
**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: [August 10, 2023, 7:17am UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregation-orderby-in-java-client-8-8-2/340514/1 "2023-08-10T07:17:16Z")

</div>

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

```auto
Map<String, CompositeAggregationSource> cas = new HashMap<>();
List<NamedValue<SortOrder>> orderby = new ArrayList<>();
orderby.add(NamedValue.of(key, SortOrder.Asc));

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

```

---

<div class="post-metadata">

### Author: ![swallez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swallez/32/11972_2.png) [@swallez](https://discuss.elastic.co/u/swallez)
#### Post date: [August 10, 2023, 8:14am UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregation-orderby-in-java-client-8-8-2/340514/2 "2023-08-10T08:14:44Z")

</div>

Can you please provide more details about the "parse exception" so that we can investigate?

---

<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: [August 10, 2023, 8:22am UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregation-orderby-in-java-client-8-8-2/340514/3 "2023-08-10T08:22:34Z")

</div>

[co.elastic.clients.elasticsearch.\_types.ElasticsearchException: [es/search] failed: [x\_content\_parse\_exception] [1:194] [composite] failed to parse field [sources]]

This is the exact error I'm getting in the console while running this. without order it works fine.

---

<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: [August 10, 2023, 8:31am UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregation-orderby-in-java-client-8-8-2/340514/4 "2023-08-10T08:31:01Z")

</div>

This is what generates using the above method.

"CompositeAggregationSource: {"terms":{"field":"KEY","order":[{"KEY":"asc"}]}}"

But it should be

"CompositeAggregationSource": { "terms": { "field": "KEY", "order": "asc" } }

---

<div class="post-metadata">

### Author: ![swallez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swallez/32/11972_2.png) [@swallez](https://discuss.elastic.co/u/swallez)
#### Post date: [August 10, 2023, 8:59am UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregation-orderby-in-java-client-8-8-2/340514/5 "2023-08-10T08:59:32Z")

</div>

Thanks. This is a known issue. We're working on it and this will be fixed in an upcoming release. Subscribe to the issue to follow resolution:

- [fix composite aggregation, terms, histogram, date\_histogram and geoti… by Anaethelion · Pull Request #2151 · elastic/elasticsearch-specification · GitHub](https://github.com/elastic/elasticsearch-specification/pull/2151)
- [[composite] failed to parse field [sources] · Issue #534 · elastic/elasticsearch-java · GitHub](https://github.com/elastic/elasticsearch-java/issues/534)

---

<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: [August 10, 2023, 9:11am UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregation-orderby-in-java-client-8-8-2/340514/6 "2023-08-10T09:11:23Z")

</div>

Okay. Thank you Sylvain.

---

<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: [September 7, 2023, 9:12am UTC](https://discuss.elastic.co/t/elasticsearch-composite-aggregation-orderby-in-java-client-8-8-2/340514/7 "2023-09-07T09:12:15Z")

</div>

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