Custom "Order By" Aggregation for Kibana Bar Chart

I have a bar chart and have used split series into 2 time buckets - the past 3 months (now/M-3M to now/M), and 3 months prior to that (now/M-6M to now/M-3M).

I would simply like to order the chart by the values of only the past 3 months (now/M-3M to now/M), rather than the summation of the 2 buckets.

I figured I would need to use the JSON input under Order By > Custom Metric, with the following code:
{ "query" : {"range": { "time_parm": { "gte" : "now/M-3M" }}}}

The above code gives an "Internal Server Error". How can I do this? Please help!

Kibana 7.1.0

Unfortunately you can't put a query inside a metric definition. However if you put the "Split series" aggregation first (above the X-Axis aggregation), then the visualization will plot the terms in the order of the first bucket of the top level aggregation which is the behavior you need:

  • Split series by your time ranges
  • X axis terms aggregation sort by the metric you need (as this is nested within the ranges aggregation, the ordering will be done separately for both series - as bars can only appear in one of the two orders, the order of the first defined range is picked)

thank you! This was helpful. However, for some reason, regardless of the order I put the date ranges in, it will only order by the oldest date range (which, unfortunately, is not the one I want)

Purple: Last 3 months
Blue: 6 months ago - 3 months ago

Ah, I missed that. Seems like Elasticsearch is doing some implicit ordering for ranges. Can you try using the "filters" aggregation instead with the same ranges? At least for my tests this orders them by Filter 1.

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