Painless new behaviour for nulls in version 7.x

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?

This behavior is expected starting in 7.0 (see 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.

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