# Sorting in Discover not working

**URL:** <https://discuss.elastic.co/t/sorting-in-discover-not-working/204626>\
**Category:** Kibana\
**Created:** [October 22, 2019, 10:34am UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626 "2019-10-22T10:34:17Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ssingh12](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@Ssingh12](https://discuss.elastic.co/u/Ssingh12)\
**Post date:** [October 22, 2019, 10:34am UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/1 "2019-10-22T10:34:17Z")

</div>

Hi,

I am struggling to a seeming humble issue. I am not able to get the sorting by fields work on the 'Discover'.  
So, in Discover, I 'added' a few fields to view and tried clicking on sort up/down arrows. The sorting is not working for any field except for the 'time' field. I tried this on String and also numeric fields. I also noticed, that for some fields the sort 'up/down' arrows do not show up.  
I am wondering if enabling sorting and getting it to work expectedly needs some specific changes somewhere - may be mappings file or elsewhere. I am not sure.

I read the docs and did not come across any particulars for any additional configurations. Seems like it should work easily and by default.  
I am using 7.4.0.

Any help will be highly appreciated.

---

<div class="post-metadata">

**Author:** ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)\
**Post date:** [October 22, 2019, 4:44pm UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/2 "2019-10-22T16:44:42Z")

</div>

Hello,

yeah this is a bit confusing. So when you sort on timestamp - that is your primary sort and the other secondary sorts depend on it.

@Bargs can you please grab this one?

Thanks,  
Bhavya

---

<div class="post-metadata">

**Author:** ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)\
**Post date:** [October 22, 2019, 9:24pm UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/3 "2019-10-22T21:24:04Z")

</div>

As Bhavya mentioned you might be getting tricked by the way multi-sort works. You can sort on multiple fields in Discover now. The first one you click on (or the one that is already selected in timestamp's case) will be your primary sort. The next one you click on will be your secondary sort. If you don't want to sort on timestamp, just click the arrow in the timestamp column again to remove that sort. There are tooltips on the arrow buttons to help you understand what each click will do.

About the fields without sort buttons: these are probably not sortable due to how they're mapped. `text` fields are not sortable by default. If you have a `keyword` version of that `text` field then you can sort on that. The `keyword` fields usually don't show up by default in the sidebar because they're typically multi fields that don't exist in the source document. You can make them visible in the sidebar (so they can be added as columns) by opening the settings in the sidebar and unchecking "Hide missing fields".

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

---

<div class="post-metadata">

**Author:** ![Ssingh12](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@Ssingh12](https://discuss.elastic.co/u/Ssingh12)\
**Post date:** [October 23, 2019, 4:52am UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/4 "2019-10-23T04:52:05Z")

</div>

Hi @Bargs, @bhavyarm, thanks a ton. Thats exactly what was tricking me. Also, I find the information about using multi-fields in Discover and for sort also very useful.  
This sorts me out. Thanks guys!

Edit: I am also using scripted fields because I need pretty names for my fields. Your responses got the sorting to work for all fields - scripted, normal and also multi-fields. However, now there is another issue I am facing. In the discover table data, I can hover over any cell and click on it to add a filter. This filter works when the field is normal, but if its a scripted field, the filter does not work. Any idea?

---

<div class="post-metadata">

**Author:** ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)\
**Post date:** [October 24, 2019, 2:54am UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/5 "2019-10-24T02:54:24Z")

</div>

> [@Ssingh12](#):
>
> I am also using scripted fields because I need pretty names for my fields

If you only need nice display names, have you tried using a [field formatter](https://www.elastic.co/guide/en/kibana/7.4/field-formatters-string.html)? These can be more lightweight performance-wise because the formatting is done in the browser rather than in Elasticsearch. Search will be more performant if done against regular fields vs a script.

If a field formatter won't do the job for you, could you open up your browser's dev tools and see if there's an error when filtering on the scripted field? Filter on scripted fields should work, so there must be something funny going on.

---

<div class="post-metadata">

**Author:** ![Ssingh12](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@Ssingh12](https://discuss.elastic.co/u/Ssingh12)\
**Post date:** [October 24, 2019, 6:16am UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/6 "2019-10-24T06:16:47Z")

</div>

@Bargs, I looked into field formatter. I want to format the field 'names' not 'values', so I think it won't help me.  
I raised another topic for the filtering here - [How to 'filter' in Discover when the field is a scripted field](https://discuss.elastic.co/t/how-to-filter-in-discover-when-the-field-is-a-scripted-field/204890). @Larry_Gregory tells me its a known limitation.  
Now, I am thinking of alternate solutions.  
The only reason I had to use scripted fields was prettier names for the fields. The script only contained reassignment of the same value to another field with a prettier name.  
I would like to try Aliases or ditch the prettier names altogether.

---

<div class="post-metadata">

**Author:** ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)\
**Post date:** [October 24, 2019, 9:38pm UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/7 "2019-10-24T21:38:46Z")

</div>

Field aliases would be an ideal solution, but unfortunately Kibana does not support them well at the moment [https://github.com/elastic/kibana/issues/21705](https://github.com/elastic/kibana/issues/21705)

---

<div class="post-metadata">

**Author:** ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)\
**Post date:** [October 24, 2019, 9:41pm UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/8 "2019-10-24T21:41:06Z")

</div>

Personally, if ditching the pretty names for the time being is an option, I would do that instead of creating scripted fields just for that purpose. Scripted fields will have a major impact on performance when used in filtering and aggregations so it is a big cost to pay for having nicer field names.

---

<div class="post-metadata">

**Author:** ![Ssingh12](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@Ssingh12](https://discuss.elastic.co/u/Ssingh12)\
**Post date:** [October 25, 2019, 5:43am UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/9 "2019-10-25T05:43:53Z")

</div>

Right, we will ditch pretty field names until Kibana supports it..

---

<div class="post-metadata">

**Author:** ![Ssingh12](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@Ssingh12](https://discuss.elastic.co/u/Ssingh12)\
**Post date:** [October 31, 2019, 5:03am UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/10 "2019-10-31T05:03:39Z")

</div>

Hi @Bargs @bhavyarm,

I am back with another doubt.  
I have ditched the 'pretty labels' in discover table. We are using discover table for showing documents, sorting on columns and filtering on fields. In order for sorting to work on for 'text' columns, I have to use the .keyword variant of the field. I could easily added the .keyword variants to discover table, however, they do not show a value. They are all empty. I cross-checked by adding the .text variant and the column has data. So, for same fields, the .keyword has no data while the normal/main field has data.  
This is getting at me. I was thinking of making the .keyword and main field and .text as multi-field. But, this will not fully solve my problem. I also have dynamic fields and for which Kibana creates the main field with .text analysis and multi-field with .keyword analysis. So, for multi-fields the issue will still continue.

Suggestions on how to get around with it?

Thanks..

---

<div class="post-metadata">

**Author:** ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)\
**Post date:** [October 31, 2019, 9:58pm UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/11 "2019-10-31T21:58:46Z")

</div>

Have you tried using [dynamic templates](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/dynamic-templates.html) in your index mappings? This should allow you to control how text fields are dynamically mapped.

---

<div class="post-metadata">

**Author:** ![Ssingh12](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@Ssingh12](https://discuss.elastic.co/u/Ssingh12)\
**Post date:** [November 1, 2019, 6:51am UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/12 "2019-11-01T06:51:15Z")

</div>

Thanks. I tried that and it worked!. Phew.. that was a lot of work to just get the discover table working per expectations.

---

<div class="post-metadata">

**Author:** ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)\
**Post date:** [November 1, 2019, 7:26pm UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/13 "2019-11-01T19:26:23Z")

</div>

Yeah, handling of multi fields is still not ideal by a long shot. There is a ticket in github for this issue [https://github.com/elastic/kibana/issues/7419](https://github.com/elastic/kibana/issues/7419)

It's possible this issue will get some traction soon, because we're now storing the field information we need in Kibana to understand the relationship between fields and their multi-fields, and the discover doc table will be getting some love soon.

---

<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:** [November 29, 2019, 7:26pm UTC](https://discuss.elastic.co/t/sorting-in-discover-not-working/204626/14 "2019-11-29T19:26:33Z")

</div>

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