# Sub aggregation graph ordering off first bucket, not overall data set

**URL:** <https://discuss.elastic.co/t/sub-aggregation-graph-ordering-off-first-bucket-not-overall-data-set/132216>\
**Category:** Kibana\
**Created:** [May 16, 2018, 9:10pm UTC](https://discuss.elastic.co/t/sub-aggregation-graph-ordering-off-first-bucket-not-overall-data-set/132216 "2018-05-16T21:10:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ogtool](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ogtool/32/18767_2.png) [@ogtool](https://discuss.elastic.co/u/ogtool)\
**Post date:** [May 16, 2018, 9:10pm UTC](https://discuss.elastic.co/t/sub-aggregation-graph-ordering-off-first-bucket-not-overall-data-set/132216/1 "2018-05-16T21:10:57Z")

</div>

I've attempted to search for anything similar on Google/here before posting this, but apologies if I've missed anything.

Using a time series graph (replicated on vertical bar and line) we're plotting Unique Count of usernames over time with the X Axis sub-bucketed by Term (country). While the data returned is correct, the way in which data is ordered (within the sub-aggs and the legend) is not what I expected.

Current result:

- The order of sub-buckets only seems to be based off the values returned in the first bucket. As the first bucket in our data set is an outlier (Brazil is 3rd, Mexico is 4th) it carries this through the rest of the graph, where both are clearly well down the list if you considered the entire data set

Expected result:

- All buckets in the time series should be considered when calculating the order of buckets

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/c/4c192a61f9b31742672023cc9480846abba32455.png)

Cheers, CCM

---

<div class="post-metadata">

**Author:** ![spalger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spalger/32/14092_2.png) [@spalger](https://discuss.elastic.co/u/spalger)\
**Post date:** [May 16, 2018, 9:28pm UTC](https://discuss.elastic.co/t/sub-aggregation-graph-ordering-off-first-bucket-not-overall-data-set/132216/2 "2018-05-16T21:28:27Z")

</div>

Sounds like you're running into [https://github.com/elastic/kibana/issues/17532](https://github.com/elastic/kibana/issues/17532). You might want to update that with any additional details you can provide and subscribe for updates there.

---

<div class="post-metadata">

**Author:** ![ogtool](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ogtool/32/18767_2.png) [@ogtool](https://discuss.elastic.co/u/ogtool)\
**Post date:** [May 17, 2018, 5:13pm UTC](https://discuss.elastic.co/t/sub-aggregation-graph-ordering-off-first-bucket-not-overall-data-set/132216/3 "2018-05-17T17:13:21Z")

</div>

Thanks @spalger - appreciate you pointing out the github issue. I'll update with info relevant to our case.

CCM

---

<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 14, 2018, 5:13pm UTC](https://discuss.elastic.co/t/sub-aggregation-graph-ordering-off-first-bucket-not-overall-data-set/132216/4 "2018-06-14T17:13:35Z")

</div>

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