# Painless new behaviour for nulls in version 7.x

**URL:** <https://discuss.elastic.co/t/painless-new-behaviour-for-nulls-in-version-7-x/212096>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [December 17, 2019, 5:21am UTC](https://discuss.elastic.co/t/painless-new-behaviour-for-nulls-in-version-7-x/212096 "2019-12-17T05:21:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paulo\_Henrique\_PH](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paulo_henrique_ph/32/14831_2.png) [@Paulo\_Henrique\_PH](https://discuss.elastic.co/u/Paulo_Henrique_PH)\
**Post date:** [December 17, 2019, 5:21am UTC](https://discuss.elastic.co/t/painless-new-behaviour-for-nulls-in-version-7-x/212096/1 "2019-12-17T05:21:34Z")

</div>

Hi all,

After the upgrade from version 6 to 7, we are experiencing a new behavior when processing aggregation. Now, whenever the Elastic comes across with a null value in a field while running a Painless script **it breaks** , by default.

For example, the following simple if/else statement:

```
if(doc['MY_FIELD'].value <= 9000) 
{return 'Less than 9k' }
else if(doc['MY_FIELD'].value > 9000)
{ return ''More than 9k' }

```

Until version 6, we could run this code without any issue whatsoever. However now, if you try the same thing it fails when Elastic processes a single null value for the field.

```
  "lang" : "painless",
  "caused_by" : {
    "type" : "illegal_state_exception",
    "reason" : "A document doesn't have a value for a field! Use doc[<field>].size()==0 to check if a document is missing a field!"

```

That makes now mandatory to stuff this "`doc[<field>].size()==0`" checking everywhere.

Is that a parameter to shut this new behavior off and resume the previous one?  
Thanks

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [December 19, 2019, 1:56am UTC](https://discuss.elastic.co/t/painless-new-behaviour-for-nulls-in-version-7-x/212096/2 "2019-12-19T01:56:23Z")

</div>

This behavior is expected starting in 7.0 (see [https://github.com/elastic/elasticsearch/issues/29286](https://github.com/elastic/elasticsearch/issues/29286)). Using the `size() == 0` check for missing values is intentional. While in the past a "default" value would have been provided, this results in trappiness for users not knowing that some documents may not have a value. The error message you received is to ensure users do not fall into that trap.

---

<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:** [January 16, 2020, 1:56am UTC](https://discuss.elastic.co/t/painless-new-behaviour-for-nulls-in-version-7-x/212096/3 "2020-01-16T01:56:33Z")

</div>

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