How to show last n records in ascending order in kibana dashboard

Hi All,

We have data and time field in X axis and we are showing data on X axis from today to today+25 records. e.g 3Dec, 2 Dec, 1 Dec, 30 Nov, 29 Nov etc.
We need to show total 25 data count in reverse order.
e.g 25 Nov, 26 Nov,27 Nov, 28 Nov, ....... 2 Dec, 3 Dec, 4Dec.

Could you please suggest any solution for the same?

Hi @ajain16,

What visualization type are you using?
Could you please give a bit more input? A screenshot would help.

I am a bit confused, because by default any date-histogram on x-axis uses ascending order.

Hi Dosant,

Please find below snapshot of Descending and Ascending order.
We want to see data from today to last 25 records (e.g 4 Dec to 25th Nov ). Current we are unable to achieve the same using ascending order.
Please suggest me if there any changes is required.

Descending order:

Ascending order

Instead of using terms aggregation on x-axis and alphabetical sorting, I'd suggest to use date-histogram aggregation. For this your field should be a timestamp instead of formatted date string.


As you can see, with this you'd get a desired result on x-axis.

@dosant - If I used data histogram then I am unable to see time on X axis. In additional to this it was not showing all the dates. Please refer below snapshot.
Do you have any solution for the problem.?

So your requirement is to display exact data and time per bar on x-axis? Then indeed I think data-histogram wouldn't work and terms seems more appropriate :frowning_face:

Maybe you can change formatting of your start string such that alpabetical sorting matches time sorting?

  • 2020-11-04 | 05:00
  • 2020-11-05 | 06:00
  • 2020-12-04 | 18:00

@dosant - We already have tried with the alphabetical sorting. But still it is not working.

What if you'd also setup a time range filter to filter on a specific time interval (to get last ~25 records)

Screenshot 2020-12-08 at 11.27.11

This filter will be saved with your visualization and will be applied when viz is used on a dashboard.

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