# Scripting a Field with multiple fields with Null values

**URL:** <https://discuss.elastic.co/t/scripting-a-field-with-multiple-fields-with-null-values/284207>\
**Category:** Elasticsearch\
**Created:** [September 14, 2021, 5:05pm UTC](https://discuss.elastic.co/t/scripting-a-field-with-multiple-fields-with-null-values/284207 "2021-09-14T17:05:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkward](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pkward/32/95305_2.png) [@pkward](https://discuss.elastic.co/u/pkward)\
**Post date:** [September 14, 2021, 5:05pm UTC](https://discuss.elastic.co/t/scripting-a-field-with-multiple-fields-with-null-values/284207/1 "2021-09-14T17:05:38Z")

</div>

Hi,

I'm attempting to use a script processor to add the sum of other fields into a total field, but some of the values are null. I know that I can use a "gsub" or "set" processors to set null values to 0, but the "gsub" processor only allows strings. I also know that I can create a Dynamic template to do the conversions as well. Can anyone tell me the easiest way to set "null" values found in any field to 0? I would use the null\_value setting in my index, but the problem is that I'm trying to calculate a score before the document gets indexed.

---

<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:** [October 12, 2021, 5:06pm UTC](https://discuss.elastic.co/t/scripting-a-field-with-multiple-fields-with-null-values/284207/2 "2021-10-12T17:06:36Z")

</div>

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