[script_exception] runtime error in Discover

Hi,

I can add scripted field selfReview;

if ( doc['type.keyword'].value == "comment-added" &&
     doc['comment.keyword'].value.contains("Code-Review+2") &&
     doc['change.owner.name.keyword'].value == doc['author.name.keyword'].value  ) {
    return true;
}
return false;

The script runs fine when I run the test.
But in Discover I get [script_exception] runtime error. If I remove the above it´s works fine.

Full error message:

Error: Bad Request
    at Fetch._callee3$ (https://elk-kibana01/31997/bundles/commons.bundle.js:3:1287438)
    at l (https://elk-kibana01/31997/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:288:969217)
    at Generator._invoke (https://elk-kibana01/31997/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:288:968970)
    at Generator.forEach.e.<computed> [as next] (https://elk-kibana01/31997/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:288:969574)
    at asyncGeneratorStep (https://elk-kibana01/31997/bundles/commons.bundle.js:3:1280961)
    at _next (https://elk-kibana01/31997/bundles/commons.bundle.js:3:1281272)

hi @mats.ahlbom,

this can happen when the script fails on a particular document. e.g. when your document is sparsely populated.

You can test this by running the _search request with the script-field directly against Elasticsearch.

You can grab the request discover is running by clicking on the inspect-tab in the top right.

Copy-paste the request body and run against your index in the Kibana dev-tools.

Something like:

GET myindexpattern/_search
{
 ....request-body-grabbed-from-discover-inspect-tab-that-includes-the-scripted-field...
}

Hi @thomasneirynck,

Thanks for help!

This morning it was working for some hours.
I think I need to add a NULL check of DOC['comment']. How can I do that? Is it possible to do that in the same IF-statement?

Hi

You could use doc.containsKey('keyToCheck') to check for existence of the field in the doc to prevent the exception.

Best,
Matthias

Hi,

I change to

if ( doc.containsKey('comment') &&
     doc.containsKey('type') &&
     doc.containsKey('change') &&
     doc['type.keyword'].value == "comment-added" &&
     doc['comment.keyword'].value.contains("Code-Review+2") &&
     doc['change.owner.name.keyword'].value == doc['author.name.keyword'].value  ) {
    return true;
}
return false;

and I think it is working.

1 Like

Now I have added more checks and now I think it is working to 100% :slight_smile:

if ( doc.containsKey('comment') &&
     doc.containsKey('type') &&
     doc.containsKey('change.owner.name') &&
     doc.containsKey('author.name') &&
     doc['type.keyword'].size() > 0 &&
     doc['comment.keyword'].size() > 0 &&
     doc['change.owner.name.keyword'].size() > 0 &&
     doc['author.name.keyword'].size() > 0 &&
     doc['type.keyword'].value == "comment-added" &&
     doc['comment.keyword'].value.contains("Code-Review+2") &&
     doc['change.owner.name.keyword'].value == doc['author.name.keyword'].value  ) {
    return true;
}
return false;
2 Likes