# Having a hard time getting daysOfWeek in scripted field

**URL:** <https://discuss.elastic.co/t/having-a-hard-time-getting-daysofweek-in-scripted-field/180644>\
**Category:** Kibana\
**Created:** [May 11, 2019, 11:50am UTC](https://discuss.elastic.co/t/having-a-hard-time-getting-daysofweek-in-scripted-field/180644 "2019-05-11T11:50:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![geriberi](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@geriberi](https://discuss.elastic.co/u/geriberi)\
**Post date:** [May 11, 2019, 11:50am UTC](https://discuss.elastic.co/t/having-a-hard-time-getting-daysofweek-in-scripted-field/180644/1 "2019-05-11T11:50:32Z")

</div>

Hi,

I kind of have a hard time getting daysOfWeek work in scripted fields as also described in [Date Field API](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-expression.html#_date_field_api). I tried to look for similar problems, but i haven't found anything related in the forum.

Sample data  
`{"date":"2019-02-01","licence_type":"EPS","EPS_limit":"4567","daily_avg_eps":"1234"}`

Index patter is created as type date (with format specified "yyyy-MM-dd" for 'date', text for 'licence\_type' and integer for 'EPS\_limit' and 'daily\_avg\_eps'

So far so good, the data is shown correctly in regular graphs. For the sake of space on the dashboard (and becuase it obviously looks more fancy) I would like to use a heatmap, where one axis is a Date Histogram based on weeks and the other the calculated field daysOfWeek.

To create the scripted field I use in the specific index pattern the 'Add scripted field' possibility  
Name: day\_of\_week  
Language: priceless  
Type: date  
Format: default  
Popularity: 0  
Script  
`doc['date'].date.dayOfWeek`

In preview results it return an empty space:  
`[]`

Nevertheless I can create the field with the 'create field' button.

When I go to 'Discovery' and select the specific index then I get promted the following error message:  
`Error with Painless scripted field 'doc['date'].date.dayOfWeek'. You can address this error by editing the 'doc['date'].date.dayOfWeek' field in Management > Index Patterns, under the “Scripted fields” tab. Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"script_exception","reason":"runtime error","script_stack":["doc['date'].date.dayOfWeek"," ^---- HERE"], "script":"doc['date'].date.dayOfWeek","lang":"painless"},{"type":"script_exception","reason":"runtime error","script_stack":["doc['date'].date.dayOfWeek"," ^---- HERE"],"script":"doc['date'].date.dayOfWeek","lang":"painless"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"fetch","grouped":true,"failed_shards":[{"shard":0,"index":"km214-2018","node":"RWKFXCBRR8ajtIQs4arvug","reason":{"type":"script_exception","reason":"runtime error","script_stack":["doc['date'].date.dayOfWeek"," ^---- HERE"],"script":"doc['date'].date.dayOfWeek","lang":"painless","caused_by":{"type":"illegal_argument_exception","reason":"Illegal list shortcut value [date]."}}},{"shard":0,"index":"km214-2019","node":"RWKFXCBRR8ajtIQs4arvug","reason":{"type":"script_exception","reason":"runtime error","script_stack":["doc['date'].date.dayOfWeek"," ^---- HERE"],"script":"doc['date'].date.dayOfWeek","lang":"painless","caused_by":{"type":"illegal_argument_exception","reason":"Illegal list shortcut value [date]."}}}]},"status":400}`  
Any I ideas, why it is messing up, despite having the correct format (=date) and how I could resolve it?

Thanks for every idea in advance,  
Geri

---

<div class="post-metadata">

**Author:** ![geriberi](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@geriberi](https://discuss.elastic.co/u/geriberi)\
**Post date:** [May 12, 2019, 3:02pm UTC](https://discuss.elastic.co/t/having-a-hard-time-getting-daysofweek-in-scripted-field/180644/2 "2019-05-12T15:02:15Z")

</div>

Resolved, solution can be found here in the forum: [Filter by Day Of Week](https://discuss.elastic.co/t/bar-chart-filtered-by-day-of-week/155743)

---

<div class="post-metadata">

**Author:** ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)\
**Post date:** [May 14, 2019, 4:30pm UTC](https://discuss.elastic.co/t/having-a-hard-time-getting-daysofweek-in-scripted-field/180644/3 "2019-05-14T16:30:54Z")

</div>

Thanks for following up with the solution!

---

<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:** [June 11, 2019, 4:30pm UTC](https://discuss.elastic.co/t/having-a-hard-time-getting-daysofweek-in-scripted-field/180644/4 "2019-06-11T16:30:57Z")

</div>

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