# Kibana sorting does not work

**URL:** <https://discuss.elastic.co/t/kibana-sorting-does-not-work/123059>\
**Category:** Kibana\
**Created:** [March 8, 2018, 11:47am UTC](https://discuss.elastic.co/t/kibana-sorting-does-not-work/123059 "2018-03-08T11:47:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sridevi](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@sridevi](https://discuss.elastic.co/u/sridevi)\
**Post date:** [March 8, 2018, 11:47am UTC](https://discuss.elastic.co/t/kibana-sorting-does-not-work/123059/1 "2018-03-08T11:47:49Z")

</div>

Hi,

I am trying to sort the data in Kibana visualization. When i try to sort the data in descending order, it treats 10 is less than 9.

it sorts 10\_1\_0 less than 9\_1\_0. In fact it sorts 10\_1\_0 less than 1\_1\_0. Please help me.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 8, 2018, 11:52am UTC](https://discuss.elastic.co/t/kibana-sorting-does-not-work/123059/2 "2018-03-08T11:52:04Z")

</div>

That is the correct natural sorting order for strings. If you want it to sort correctly as a string, I suspect you will need to make sure strings are the same length using leading zeros. `9_1_0` \> `10_1_0`, but `10_1_0` \> `09_1_0`. Another solution would be to store the different parts as an integer with fixed number of digits for minor and patch level, e.g. `90100` and `100100`.

---

<div class="post-metadata">

**Author:** ![sridevi](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@sridevi](https://discuss.elastic.co/u/sridevi)\
**Post date:** [March 8, 2018, 12:04pm UTC](https://discuss.elastic.co/t/kibana-sorting-does-not-work/123059/3 "2018-03-08T12:04:28Z")

</div>

Thanks for the reply. As I mentioned above, Kibana doing sorting in visualization. Any possibility to change the query and aggregation below?

Kibana table query looks like below:  
{  
"query": {  
"bool": {  
"must": [  
{  
"query\_string": {  
"analyze\_wildcard": true,  
"query": "tag:xxx-1\*_\*_\*"  
}  
},  
{  
"range": {  
"time\_stamp": {  
"gte": 1362742674401,  
"lte": 1520509074401,  
"format": "epoch\_millis"  
}  
}  
}  
],  
"must\_not": []  
}  
},  
"size": 0,  
"\_source": {  
"excludes": []  
},  
"aggs": {  
"3": {  
"terms": {  
"field": "\_type",  
"size": 7,  
"order": {  
"\_term": "desc"  
}  
}  
}

---

<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:** [April 5, 2018, 12:04pm UTC](https://discuss.elastic.co/t/kibana-sorting-does-not-work/123059/4 "2018-04-05T12:04:36Z")

</div>

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