dateRange aggregations order

Enonic version: 7.2.0

Is there a way to ordernate the dataRange aggregation result? Is it ASC by default ?

Could you show your query and what the expected result, please?

Maybe you need date histogram? https://developer.enonic.com/docs/xp/stable/storage/aggregations#datehistogram

As for ranges, since they may overlap, ordering of aggregation results is left for the client. There is no default order.

1 Like

I’m using this aggregation to count the quantity of files by range:

aggregations: {
    publishedTime: {
        dateRange: {
            field: 'publish.from',
            format: 'dd.MM.yyyy',
            ranges: [
                {
                    from: 'now-7d'
                },
                {
                    from: 'now-1M'
                },
                {
                    from: 'now-3M'
                },
                {
                    from: 'now-1y'
                },
                {
                    to: 'now'
                }
            ]
        }
    }
}

and i’m getting this output in log.info() using JSON.stringify() function in the aggregations key:

I believe the default behavior is ASC ordening by the from key, but would be nice to see that on documentation.

We don’t document the order because there is no order. Your observation is a coincidence. Don’t rely on it, as it may (and will) change when we update search engine.

Here is an example to it may happen: