Scripted fields don't work after upgrading to 7.1

Hi everyone,

I recently upgrade my cluster to 7.1 and my scripted fields (created in 6.6) don't work anymore.

Explanation of the scripted fields:
I want to merge 4 values into 1 values in 1 fields. Theses 4 values are :
-action.keyword : Deny
-action.keyword : Denied
-action.keyword : denied
-action.keyword : denied by ACL.

If the script found this value in the field "action.keyword" return a string value "Deny".
The aim is to combine all the "Deny's" in the action field.

Please find below my script:
if ((doc['action.keyword'].value == 'Deny') || (doc['action.keyword'].value == 'denied') || (doc['action.keyword'].value == 'denied by ACL') || (doc['action.keyword'].value == 'Denied')) { return 'Deny'; } return '';

This script was working like a charm in 6.6. Please find below a sample of the error in the log of ES:

[2019-06-14T11:43:58,233][DEBUG][o.e.a.s.TransportSearchAction] [hostname] [1025278] Failed to execute fetch phase
org.elasticsearch.transport.RemoteTransportException: [hostname][host_ip:9300][indices:data/read/search[phase/fetch/id]]
Caused by: org.elasticsearch.script.ScriptException: runtime error
Caused by: java.lang.IllegalStateException: A document doesn't have a value for a field! Use doc[].size()==0 to check if a document is missing a field!

When I apply this scripted field I don't see any log for the index pattern where i create the scripted field and this appear in the selected fields:
image

and
image

I even tried to do a basic script like :
doc['action.keyword'].value + ':' + doc['direction.keyword'].value
but same error as above

Also, when i try apply the recommendation doc['action.keyword'].size()==0 the value is "false" and I can view my log and don't have any errors.

Could you please help me with this issue?
Thank you very much
Thibaut

Hi @Thibaut_M,

Yes, it's a breaking change in ES mentioned here. Can't you just prepend you script with another if?

if (doc['action.keyword'].size() == 0) return '';
if ((doc['action.keyword'].value == 'Deny') || (doc['action.keyword'].value == 'denied') || (doc['action.keyword'].value == 'denied by ACL') || (doc['action.keyword'].value == 'Denied')) { return 'Deny'; } return '';

Best,
Oleg

Hi Azasypkin,

Thank you it work :slight_smile:

Regards,
Thibaut

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