# Keep getting null in field scripting

**URL:** <https://discuss.elastic.co/t/keep-getting-null-in-field-scripting/226472>\
**Category:** Kibana\
**Created:** [April 3, 2020, 7:57pm UTC](https://discuss.elastic.co/t/keep-getting-null-in-field-scripting/226472 "2020-04-03T19:57:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Incauto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/incauto/32/60149_2.png) [@Incauto](https://discuss.elastic.co/u/Incauto)\
**Post date:** [April 3, 2020, 7:57pm UTC](https://discuss.elastic.co/t/keep-getting-null-in-field-scripting/226472/1 "2020-04-03T19:57:51Z")

</div>

Hi, not all documents has the field "seconds", so I check for it, and then check if the value is not null, but I keep getting null results,

```auto
if (doc.containsKey('seconds')){
    if (doc['seconds'].value != null){
        return doc['seconds'].value;
    }
}

```

Any clues on what is happening?

the field is a number  
return type number  
elk 7.51

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [April 7, 2020, 7:59pm UTC](https://discuss.elastic.co/t/keep-getting-null-in-field-scripting/226472/2 "2020-04-07T19:59:01Z")

</div>

The return type is `number` only when the `if` is true.

To me, it looks like the script needs another `return` and the end, and provide a fallback when the value is null.

---

<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:** [May 5, 2020, 8:11pm UTC](https://discuss.elastic.co/t/keep-getting-null-in-field-scripting/226472/3 "2020-05-05T20:11:45Z")

</div>

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