# Datehistogram Composite Agg Sort Error in new Java Client

**URL:** https://discuss.elastic.co/t/datehistogram-composite-agg-sort-error-in-new-java-client/332695
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [May 6, 2023, 6:27am UTC](https://discuss.elastic.co/t/datehistogram-composite-agg-sort-error-in-new-java-client/332695 "2023-05-06T06:27:19Z")
**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:27am UTC](https://discuss.elastic.co/t/datehistogram-composite-agg-sort-error-in-new-java-client/332695/1 "2023-05-06T06:27:19Z")

</div>

I am getting error when giving sort in Datehistogram composite agg

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

my code as below

```auto
Map<String, CompositeAggregationSource> map = new HashMap<>();
            map.put("datehistogram",
                    new CompositeAggregationSource.Builder().dateHistogram(d->d
                                    .order(NamedValue.of("_key",SortOrder.Desc))
                                    .timeZone("UTC")
                                    .field("@timestamp")
                                    .calendarInterval(CalendarInterval.Day)
                            ).build()
                    );

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

```

How to give sort in composite Agg Datehistogram ?

---

<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:28am UTC](https://discuss.elastic.co/t/datehistogram-composite-agg-sort-error-in-new-java-client/332695/2 "2023-06-03T06:28:18Z")

</div>

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