# Trouble using new .order() on datehistogram after upgrading

**URL:** <https://discuss.elastic.co/t/trouble-using-new-order-on-datehistogram-after-upgrading/369224>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [October 22, 2024, 1:01pm UTC](https://discuss.elastic.co/t/trouble-using-new-order-on-datehistogram-after-upgrading/369224 "2024-10-22T13:01:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krikkits](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krikkits/32/125421_2.png) [@Krikkits](https://discuss.elastic.co/u/Krikkits)\
**Post date:** [October 22, 2024, 1:01pm UTC](https://discuss.elastic.co/t/trouble-using-new-order-on-datehistogram-after-upgrading/369224/1 "2024-10-22T13:01:55Z")

</div>

I recently upgraded to Spring 3 which means there were small adjustments needed for some of my queries/aggregations written in elasticsearch java. I cannot figure out how to get the .order(SortOrder.Asc) to work again in the current version. This is what my Aggregation used to look like:

```auto
new Aggregation.Builder().dateHistogram(
         d -> d.field("timestamp")
            .calendarInterval(...)
            .format(...)
            .order(HistogramOrder.of(h -> h.key(SortOrder.Asc)))
            .minDocCount(0)
            .extendedBounds(
               e -> e.max(...)
                  .min(...)
            )
      );

```

now the .order(...) seems to take a NamedValue, so I tried

```auto
.order(NamedValue.of("ascending", SortOrder.Asc))

```

this however, only gives me an error when trying to execute the query:  
"type":"aggregation\_execution\_exception","reason":"Invalid aggregation order path [ascending]. The provided aggregation [ascending] either does not exist, or is a pipeline aggregation and cannot be used to sort the buckets."

I can't say I understand the error completely and how to fix it! Is there a different way of ordering these buckets now? Any help appreciated!

---

<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:** [October 24, 2024, 8:26am UTC](https://discuss.elastic.co/t/trouble-using-new-order-on-datehistogram-after-upgrading/369224/2 "2024-10-24T08:26:04Z")

</div>

Hello!

`order` works the same in any aggregation, and in Java it's a NamedValue because you have to choose:

1. what you need to order by (keyword? aggregation?)
2. how you want to order it. (asc? desc?)

In the previous version of the client we'd hardcoded a few choices, like `key` in the example you showed which is equivalent to:

```auto
...
"order": { "_key": "asc" }
...

```

While in the new client we the parameter as a string, because you can also order by sub aggregation names - so in the new client all you need to do is replace `ascending` with `_key`, or whatever parameter you need to order the buckets by!

You can find more information on how to use `order` in the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-order) (yes it's term aggregation, because as I said it works the same for every aggregation).
