# Sorting issue on keyword

**URL:** <https://discuss.elastic.co/t/sorting-issue-on-keyword/231133>\
**Category:** Kibana\
**Created:** [May 5, 2020, 10:42am UTC](https://discuss.elastic.co/t/sorting-issue-on-keyword/231133 "2020-05-05T10:42:14Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![formiaczek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/formiaczek/32/67778_2.png) [@formiaczek](https://discuss.elastic.co/u/formiaczek)\
**Post date:** [May 6, 2020, 9:43am UTC](https://discuss.elastic.co/t/sorting-issue-on-keyword/231133/4 "2020-05-06T09:43:17Z")

</div>

This is not as much about the legend @Larry_Gregory, as about the 'Order By' being broken for split-series.

(i.e. forget about the 'legend' - it's not that important really).

There is a bug that can be shown using your demo [here](https://demo.elastic.co/app/kibana#/visualize/create?type=horizontal_bar&indexPattern=90943e30-9a47-11e8-b64d-95841ca0b247&_g=(refreshInterval:(pause:!t,value:0),time:(from:now-7d,mode:quick,to:now))&_a=(filters:!(),linked:!f,query:(language:kuery,query:''),uiState:(),vis:(aggs:!((enabled:!t,id:'1',params:(),schema:metric,type:count),(enabled:!t,id:'2',params:(field:tags.keyword,missingBucket:!f,missingBucketLabel:Missing,order:asc,orderBy:'1',otherBucket:!f,otherBucketLabel:Other,size:7),schema:group,type:terms),(enabled:!t,id:'3',params:(field:machine.os.keyword,missingBucket:!t,missingBucketLabel:Missing,order:desc,orderBy:'1',otherBucket:!f,otherBucketLabel:Other,size:5),schema:segment,type:terms)),params:(addLegend:!t,addTimeMarker:!f,addTooltip:!t,categoryAxes:!((id:CategoryAxis-1,labels:(filter:!f,rotate:0,show:!t,truncate:200),position:left,scale:(type:linear),show:!t,style:(),title:(),type:category)),dimensions:(series:!((accessor:0,aggType:terms,format:(id:terms,params:(id:string,missingBucketLabel:Missing,otherBucketLabel:Other)),params:())),x:(accessor:1,aggType:terms,format:(id:terms,params:(id:string,missingBucketLabel:Missing,otherBucketLabel:Other)),params:()),y:!((accessor:2,aggType:count,format:(id:number),params:()))),grid:(categoryLines:!f,style:(color:%23eee)),labels:(),legendPosition:right,seriesParams:!((data:(id:'1',label:Count),drawLinesBetweenPoints:!t,mode:normal,show:!t,showCircles:!t,type:histogram,valueAxis:ValueAxis-1)),thresholdLine:(color:%2334130C,show:!f,style:full,value:10,width:1),times:!(),type:histogram,valueAxes:!((id:ValueAxis-1,labels:(filter:!t,rotate:75,show:!t,truncate:100),name:LeftAxis-1,position:bottom,scale:(mode:normal,type:linear),show:!t,style:(),title:(text:Count),type:value))),title:'',type:horizontal_bar)))

Now - WinXP, count for 'error' (25), is bigger than count for 'login'(21) - but they come in different order.

Play with 'Ascending' vs 'Descending' and this seems persistent. I see this issue elsewhere in my Kibana graphs and noticed the following too:

- looks like the sorting might be applied to 'majority' of events, thus outliers will be sorted in a wrong way (not individually)? Why??

- changing value of 'Size' affects the issue (for some reason I see that going above 5 exposes it, but might be a coincident and this is really a result of the 'majority-sorting' above)

I belive odrer of labels simply follows this 'majority sorting'. And it would also explain why @Xavier_Romero can see it 'sometimes' ( I can see it on my graps 'sometimes' too: probably this is when 'majority' flips things in the 'wrong' way..

Could this be looked into / solved? If not, what is the best way to AVOID this issue and, for bar charts (not necessarily for charts like attached here) - make them 'show the truth' and not 'lie' about the order for points where this order changes? Some other charts that can be used?

Thank you!

Update:

Now there might be even a bigger bug there, when, in the above 'demo' example I reduce 'size' for X-axis aggregation to 4, chart goes awry.. and:

- number of X-axis points does NOT decrease to 4 (should this be expected?)
- some tags go missing (in IOS only 3 left, etc)

Again - play yourself [here](https://demo.elastic.co/app/kibana#/visualize/create?type=horizontal_bar&indexPattern=90943e30-9a47-11e8-b64d-95841ca0b247&_g=(refreshInterval:(pause:!t,value:0),time:(from:now-7d,mode:quick,to:now))&_a=(filters:!(),linked:!f,query:(language:kuery,query:''),uiState:(),vis:(aggs:!((enabled:!t,id:'1',params:(),schema:metric,type:count),(enabled:!t,id:'2',params:(field:tags.keyword,missingBucket:!f,missingBucketLabel:Missing,order:asc,orderBy:'1',otherBucket:!f,otherBucketLabel:Other,size:7),schema:group,type:terms),(enabled:!t,id:'3',params:(field:machine.os.keyword,missingBucket:!t,missingBucketLabel:Missing,order:desc,orderBy:'1',otherBucket:!f,otherBucketLabel:Other,size:4),schema:segment,type:terms)),params:(addLegend:!t,addTimeMarker:!f,addTooltip:!t,categoryAxes:!((id:CategoryAxis-1,labels:(filter:!f,rotate:0,show:!t,truncate:200),position:left,scale:(type:linear),show:!t,style:(),title:(),type:category)),dimensions:(series:!((accessor:0,aggType:terms,format:(id:terms,params:(id:string,missingBucketLabel:Missing,otherBucketLabel:Other)),params:())),x:(accessor:1,aggType:terms,format:(id:terms,params:(id:string,missingBucketLabel:Missing,otherBucketLabel:Other)),params:()),y:!((accessor:2,aggType:count,format:(id:number),params:()))),grid:(categoryLines:!f,style:(color:%23eee)),labels:(),legendPosition:right,seriesParams:!((data:(id:'1',label:Count),drawLinesBetweenPoints:!t,mode:normal,show:!t,showCircles:!t,type:histogram,valueAxis:ValueAxis-1)),thresholdLine:(color:%2334130C,show:!f,style:full,value:10,width:1),times:!(),type:histogram,valueAxes:!((id:ValueAxis-1,labels:(filter:!t,rotate:75,show:!t,truncate:100),name:LeftAxis-1,position:bottom,scale:(mode:normal,type:linear),show:!t,style:(),title:(text:Count),type:value))),title:'',type:horizontal_bar))) to see this in 'action'.

Seems not right to me, or it requires a really good explanation..

---

_[View the full topic](https://discuss.elastic.co/t/sorting-issue-on-keyword/231133)._
