# Sorting in KQL

**URL:** <https://discuss.elastic.co/t/sorting-in-kql/270711>\
**Category:** Kibana\
**Created:** [April 20, 2021, 1:23pm UTC](https://discuss.elastic.co/t/sorting-in-kql/270711 "2021-04-20T13:23:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mortenb123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mortenb123/32/37227_2.png) [@mortenb123](https://discuss.elastic.co/u/mortenb123)\
**Post date:** [April 20, 2021, 1:23pm UTC](https://discuss.elastic.co/t/sorting-in-kql/270711/1 "2021-04-20T13:23:24Z")

</div>

Hi, I know I can sort in Elastic api and in kibana, but now I have to use an api which only have KQL input which it encodes in base64 and send to elasticsearch. (external service)

I've tried all instances of `id: desc``sort id desc`. the response is completely random within the range.

---

<div class="post-metadata">

**Author:** ![mutt13y](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mutt13y/32/74962_2.png) [@mutt13y](https://discuss.elastic.co/u/mutt13y)\
**Post date:** [April 20, 2021, 1:26pm UTC](https://discuss.elastic.co/t/sorting-in-kql/270711/2 "2021-04-20T13:26:55Z")

</div>

You can sort on Numeric or Date fields in Discover by clicking the triangles on the column heading. (after selecting the field)

You also need to turn timestamp sorting off the same way

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [April 20, 2021, 2:08pm UTC](https://discuss.elastic.co/t/sorting-in-kql/270711/3 "2021-04-20T14:08:00Z")

</div>

This is a common misunderstanding, so we've clarified this in the [KQL docs](https://www.elastic.co/guide/en/kibana/current/kuery-query.html). KQL is used only for filtering, and sorting is done by whichever app you are using KQL inside of.

---

<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:** [May 18, 2021, 2:08pm UTC](https://discuss.elastic.co/t/sorting-in-kql/270711/4 "2021-05-18T14:08:48Z")

</div>

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