# Scripted fields don't work after upgrading to 7.1

**URL:** <https://discuss.elastic.co/t/scripted-fields-dont-work-after-upgrading-to-7-1/185829>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [June 14, 2019, 10:06am UTC](https://discuss.elastic.co/t/scripted-fields-dont-work-after-upgrading-to-7-1/185829 "2019-06-14T10:06:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thibaut\_M](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@Thibaut\_M](https://discuss.elastic.co/u/Thibaut_M)\
**Post date:** [June 14, 2019, 10:06am UTC](https://discuss.elastic.co/t/scripted-fields-dont-work-after-upgrading-to-7-1/185829/1 "2019-06-14T10:06:25Z")

</div>

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](https://us1.discourse-cdn.com/elastic/original/3X/d/8/d869213663deaad2c50248f103453374232244ce.png)

and  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/6/066ea9c7997b57fa9f6b0beda37de23ba0536ce7.png)

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

---

<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:** [June 14, 2019, 12:40pm UTC](https://discuss.elastic.co/t/scripted-fields-dont-work-after-upgrading-to-7-1/185829/2 "2019-06-14T12:40:23Z")

</div>

Hi @Thibaut_M,

Yes, it's a breaking change in ES mentioned [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#_accessing_missing_document_values_will_throw_an_error). Can't you just prepend you script with another `if`?

```auto
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

---

<div class="post-metadata">

**Author:** ![Thibaut\_M](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@Thibaut\_M](https://discuss.elastic.co/u/Thibaut_M)\
**Post date:** [June 14, 2019, 1:50pm UTC](https://discuss.elastic.co/t/scripted-fields-dont-work-after-upgrading-to-7-1/185829/3 "2019-06-14T13:50:07Z")

</div>

Hi Azasypkin,

Thank you it work 🙂

Regards,  
Thibaut

---

<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:** [July 12, 2019, 1:51pm UTC](https://discuss.elastic.co/t/scripted-fields-dont-work-after-upgrading-to-7-1/185829/4 "2019-07-12T13:51:50Z")

</div>

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