Script field with Datefield API fails after 7.0.1 update

Hi,

I was using the datefield API to create an hour of day scriptfield - (doc['date'].date.hourOfDay + 2).

Since upgrading yo 7.0.1 this now fails and i had to delete the field to load items in the discover tab.

Error message below.

Many thanks in advance

Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"script_exception","reason":"runtime error","script_stack":["doc['date'].date.hourOfDay + 2\n\n"," ^---- HERE"],"script":"doc['date'].date.hourOfDay + 2\n\n","lang":"painless"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"fetch","grouped":true,"failed_shards":[{"shard":0,"index":"clinic-visit","node":"pz5wkIMWQ0SJrKSrRqi4cg","reason":{"type":"script_exception","reason":"runtime error","script_stack":["doc['date'].date.hourOfDay + 2\n\n"," ^---- HERE"],"script":"doc['date'].date.hourOfDay + 2\n\n","lang":"painless","caused_by":{"type":"illegal_argument_exception","reason":"Illegal list shortcut value [date]."}}}]},"status":400}

hi @AQ_Amra

What version did you upgrade from? There has some deprecations wrt. date-scripting in painless in 7.0. See https://www.elastic.co/guide/en/elasticsearch//reference/current/breaking-changes-7.0.html#_getdate_and_getdates_removed

You might just have to change it to access it by doc['date'].value. instead of with the getDate() function, as is explained here: https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-examples.html#modules-scripting-painless-dates

Thank you. i missed that depreciation.

The solution was: doc['date'].value.hour

1 Like

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