Having a hard time getting daysOfWeek in scripted field

Hi,

I kind of have a hard time getting daysOfWeek work in scripted fields as also described in 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

Resolved, solution can be found here in the forum: Filter by Day Of Week

Thanks for following up with the solution!

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