# Kibana 6.4.1: Cannot sort by term data aggregated by term

**URL:** https://discuss.elastic.co/t/kibana-6-4-1-cannot-sort-by-term-data-aggregated-by-term/151152
**Category:** Kibana
**Created:** [October 5, 2018, 5:30am UTC](https://discuss.elastic.co/t/kibana-6-4-1-cannot-sort-by-term-data-aggregated-by-term/151152 "2018-10-05T05:30:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![SpaceMoose](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spacemoose/32/35972_2.png) [@SpaceMoose](https://discuss.elastic.co/u/SpaceMoose)
#### Post date: [October 5, 2018, 5:30am UTC](https://discuss.elastic.co/t/kibana-6-4-1-cannot-sort-by-term-data-aggregated-by-term/151152/1 "2018-10-05T05:30:31Z")

</div>

Hello.

I'm interested in two things with some logsthat should--but don't seem to--be straightforward:

1. Filtering data by day-of-week (i.e., Monday, Tuesday,...,Sunday or even just numbers 1-7). I understand this is more of an Elasticsearch/Lucene issue and I'll not pursue that in this email.

2. Histogram by day-of-week. Again, this is just mapping the timestamp/date back down to a day of the week. Reading around I discovered Kibana scripted fields in their Index Patterns area of the 'Management' tool. As I understand scripted fields, I can use them for aggregation but not for indexing (if I could, the first issue above would also be addressed readily).

Googling around I found this blog post that looked helpful:

[https://blog.trifork.com/2017/09/04/kibana-histogram-on-day-of-week/](https://blog.trifork.com/2017/09/04/kibana-histogram-on-day-of-week/)

I made myself a scripted field called "day\_of\_week\_opened" that looks like this (painless):

```auto
doc['open_time'].date.dayOfWeek

```

The scripted field is just an integer valued from 1 to 7 inclusive. This works fine, as one can see from this screenshot:

 ![kibana_histo_by_num_day_of_week](https://us1.discourse-cdn.com/elastic/original/3X/3/7/377a9e9e1469a391b41af4234b72ec311ad6dce5.png)

The days Monday(1) to Sunday (7) are presented in the correct order.

Now, suppose instead I would like a more human-friendly label--say abbreviation of the name of the day of the week...I made a scripted field called dayofweek that looks like this (again, painless):

```auto
doc['open_time'].date.dayOfWeek + " (" + ["", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][doc['open_time'].date.dayOfWeek] + ")"

```

Following the logic of the aforementioned blog post I tried aggregating the data by Terms and chose my new scripted field dayofweek as the Term. Here's a screenshot...

 ![day_of_week_histo_strings_but_wrong](https://us1.discourse-cdn.com/elastic/original/3X/a/4/a4405e1a39dc36ca20d2dfdb79188212640875fe.png)

You might immediatly say "Wait! You _chose_ order by count! That's what you've done wrong" Well, yes and no. I only _chose_ this ordering because order by Term did not appear as an option.

Any thoughts on what I've done wrong, or have I revealed an undocumented feature?

Further info: I'm using kibana 6.4.1 on Chrome.

Thanks for any help/advice you might offer on this issue...

---

<div class="post-metadata">

### Author: ![thomasneirynck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomasneirynck/32/23313_2.png) [@thomasneirynck](https://discuss.elastic.co/u/thomasneirynck)
#### Post date: [October 5, 2018, 2:39pm UTC](https://discuss.elastic.co/t/kibana-6-4-1-cannot-sort-by-term-data-aggregated-by-term/151152/2 "2018-10-05T14:39:06Z")

</div>

hi @SpaceMoose,

I'm surprised you don't see the option. You're right, it's a fairly common visualization.

Here is an example of a user doing a similar bar-chart:

> **[Kibana Histogram on Day of Week](https://blog.trifork.com/2017/09/04/kibana-histogram-on-day-of-week/)**
>
> I keep track of my daily commutes to and from the office. One thing I want to know is how the different days of the week are affecting my travel duration. But when indexing all my commutes into Ela…

---

<div class="post-metadata">

### Author: ![SpaceMoose](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spacemoose/32/35972_2.png) [@SpaceMoose](https://discuss.elastic.co/u/SpaceMoose)
#### Post date: [October 6, 2018, 12:39am UTC](https://discuss.elastic.co/t/kibana-6-4-1-cannot-sort-by-term-data-aggregated-by-term/151152/3 "2018-10-06T00:39:45Z")

</div>

Hi @thomasneirynk...thanks but the link you've pasted is the same one I consulted (and pasted in above) in the original post.

I'll check on Monday when I'm back in the office but I can't help but wonder whether this may be some kind of ELK version mismatch issue (I don't maintain the stack).

---

<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 3, 2018, 12:40am UTC](https://discuss.elastic.co/t/kibana-6-4-1-cannot-sort-by-term-data-aggregated-by-term/151152/4 "2018-11-03T00:40:01Z")

</div>

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