# Sorting by keyword in Kibana Discover

**URL:** https://discuss.elastic.co/t/sorting-by-keyword-in-kibana-discover/107336
**Category:** Kibana
**Created:** [November 13, 2017, 7:18am UTC](https://discuss.elastic.co/t/sorting-by-keyword-in-kibana-discover/107336 "2017-11-13T07:18:05Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![lesz3k](https://avatars.discourse-cdn.com/v4/letter/l/bbe5ce/32.png) [@lesz3k](https://discuss.elastic.co/u/lesz3k)
#### Post date: [November 13, 2017, 7:18am UTC](https://discuss.elastic.co/t/sorting-by-keyword-in-kibana-discover/107336/1 "2017-11-13T07:18:06Z")

</div>

Hey guys,

I would like to sort the data in Kibana Discover (version 5.6.3) by a field mapped as keyword, ascending. I know that it is possible to achieve such query in Elasticsearch, below I am providing the command (relevant data grepped out for brevity):

```
curl -X GET 'http://<someurl>:<someport>/<someindex>/_search' --user <somecredentials> -d '{"query":{ "match_all": {} }, "sort":[{"epoch.keyword":{"order":"asc"}}]}' | python -m json.tool | grep epoch
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 7569 100 7500 100 69 48622 447 --:--:-- --:--:-- --:--:-- 48701
                    "epoch": "1510238524.255196",
                    "epoch": "1510238524.2578862",
                    "epoch": "1510238524.2595582",
                    "epoch": "1510238526.231628",
                    "epoch": "1510238526.2461028",
                    "epoch": "1510238526.2461133",
                    "epoch": "1510238526.2502348",
                    "epoch": "1510238526.2502463",
                    "epoch": "1510238526.2802055",
                    "epoch": "1510238526.2821074",

```

How can I implement the same query in Kibana Discover?

**EDIT** : I am also providing the link to the [stackoverflow](https://stackoverflow.com/questions/47228954/sorting-by-keyword-in-kibana-discover) post, there's also the field mapping there (couldn't fit it here because of char limits)

---

<div class="post-metadata">

### Author: ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)
#### Post date: [November 13, 2017, 3:20pm UTC](https://discuss.elastic.co/t/sorting-by-keyword-in-kibana-discover/107336/2 "2017-11-13T15:20:01Z")

</div>

Hey @lesz3k have you already created your Index Pattern in Kibana and are you able to see the data in the Discover application? Once you have the data showing up in Discover, you can click on the following to sort ascending/descending on any column:

 ![18 AM](https://us1.discourse-cdn.com/elastic/original/3X/8/e/8e3dfa0c6db1e150b23059c6beabcdf74f496768.png)

---

<div class="post-metadata">

### Author: ![lesz3k](https://avatars.discourse-cdn.com/v4/letter/l/bbe5ce/32.png) [@lesz3k](https://discuss.elastic.co/u/lesz3k)
#### Post date: [November 14, 2017, 3:52pm UTC](https://discuss.elastic.co/t/sorting-by-keyword-in-kibana-discover/107336/3 "2017-11-14T15:52:46Z")

</div>

Hey @Brandon_Kobel ,

Thanks for having a look. The issue here is that the `epoch` field is mapped as keyword in elasticsearch. Please also have a look at the field mapping that I provided in the [stackoverflow](https://stackoverflow.com/questions/47228954/sorting-by-keyword-in-kibana-discover) question.

Unfortunately, it's not good enough for me if I sort the entries by the `@timestamp` field (provided by logstash), because there can be multiple log entries at the same millisecond, therefore resulting in scrambled log entries. For this reason I would like to sort by a field that is not mapped as a date and is not truncated to milliseconds - in this case the logs from Kubernetes are with generated with nano-precision, hence I would like to sort on that representation, called `epoch` in this post.

---

<div class="post-metadata">

### Author: ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)
#### Post date: [November 14, 2017, 8:41pm UTC](https://discuss.elastic.co/t/sorting-by-keyword-in-kibana-discover/107336/4 "2017-11-14T20:41:34Z")

</div>

@lesz3k if your data is indexed as a Keyword, it'd going to use "string" based sorting on it. If you change your data to be stored as one of the [numeric datatypes](https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html) it will sort properly.

---

<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: [December 12, 2017, 8:41pm UTC](https://discuss.elastic.co/t/sorting-by-keyword-in-kibana-discover/107336/5 "2017-12-12T20:41:45Z")

</div>

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