# How to organize scripted fields in order

**URL:** <https://discuss.elastic.co/t/how-to-organize-scripted-fields-in-order/211216>\
**Category:** Kibana\
**Created:** [December 10, 2019, 4:59am UTC](https://discuss.elastic.co/t/how-to-organize-scripted-fields-in-order/211216 "2019-12-10T04:59:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamesyone](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@jamesyone](https://discuss.elastic.co/u/jamesyone)\
**Post date:** [December 10, 2019, 4:59am UTC](https://discuss.elastic.co/t/how-to-organize-scripted-fields-in-order/211216/1 "2019-12-10T04:59:53Z")

</div>

Hi, currently I created a scripted field containing the days of week and explaining how much logs have come during that day. I am currently trying to organize the days into the week order (e.g. sunday, monday, tuesday, wednesday, thursday, friday, saturday) but currently it is like this :

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

I want to be able to change the dates to the week order.

This is my script currently inserted :

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/d/6d7236288d9fea3f4901777aa3a259c1cc4f94b5.png)

["", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][doc['xxx'].value.dayOfWeek]

Let me know what works best! I tried alphabetically, descending, ascending, to no luck.

---

<div class="post-metadata">

**Author:** ![azasypkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/azasypkin/32/42216_2.png) [@azasypkin](https://discuss.elastic.co/u/azasypkin)\
**Post date:** [December 11, 2019, 4:38pm UTC](https://discuss.elastic.co/t/how-to-organize-scripted-fields-in-order/211216/2 "2019-12-11T16:38:31Z")

</div>

Hi @jamesyone,

I can't think of any "good" way of achieving this unfortunately. There is a hackish way though, you can prefix your strings with invisible character that would work if you choose `Alphabetical` in `Order by`:

```auto
[' Mon', ' Tue', ' Wed', ' Thu', ' Fri', ' Sat', ' Sun']

```

Every day name is prefixed with a char from the following table:

```auto
Number Name HTML Code Appearance
------ -------------------- --------- ----------
U+2000 En Quad &#8192; " " for Mon
U+2001 Em Quad &#8193; " " for Tue
U+2002 En Space &#8194; " " for Wed
U+2003 Em Space &#8195; " " for Thu
U+2004 Three-Per-Em Space &#8196; " " for Fri
U+2005 Four-Per-Em Space &#8197; " " for Sat
U+2006 Six-Per-Em Space &#8198; " " for Sun

```

Best,  
Oleg

---

<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:** [January 8, 2020, 4:44pm UTC](https://discuss.elastic.co/t/how-to-organize-scripted-fields-in-order/211216/3 "2020-01-08T16:44:53Z")

</div>

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