5

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

Paulo Henrique PH
  • 324
  • 1
  • 4
  • 15
  • 1
    I don't recall any option to switch this behavior back. no... It's listed in [breaking changes doc for ES7](https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.html#_accessing_missing_document_values_will_throw_an_error). The easiest would be to prepend scripts with `if (doc['MY_FIELD'].size() == 0) return '';` as we did – Andrey Borisko Dec 19 '19 at 02:15

0 Answers0