Scripted field calculation with division

Hi

I want to make a scripted field using a simple calculation by using summation and dividing, but I just keep getting 0 and the error-message:
"Unable to write index pattern! Refresh the page to get the most up to date changes for this index pattern."

I want to calculate the percentage of:
(collected_va + collected_ems10) / (expected_va + expected_ems10)

All documents contains values in all 4 fields.
expected_va and expected_ems10 is always greater than 0
collected_va and collected_ems10 is always greater than 0

I use the following code:

(doc['collected_va'].value + doc['collected_ems10'].value) / (doc['expected_va'].value + doc['expected_ems10'].value)

What do I do wrong here?

This means your user can't write the index pattern saved object, probably due to permission problems. Make sure your user has "All" permissions for the "Management > Index pattern management" privilege.