[script_exception] runtime error bad request

Hi, I am new in Kibana .So I added a scripted field in one of the index pattern. I am pretty sure the code should work fine.

if (doc['message.keyword'].value.contains('errCode')) {
return "match";
}
return "No match";

When I previewed the results, it works fine. However, when I tried to view it in Discover, it said "error loading data, [script_exception] runtime error".

Error: Bad Request
    at Fetch._callee3$ (http://localhost:5601/bundles/commons.bundle.js:3:4001197)
    at l (http://localhost:5601/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:288:970406)
    at Generator._invoke (http://localhost:5601/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:288:970159)
    at Generator.forEach.e.<computed> [as next] (http://localhost:5601/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:288:970763)
    at asyncGeneratorStep (http://localhost:5601/bundles/commons.bundle.js:3:3994720)
    at _next (http://localhost:5601/bundles/commons.bundle.js:3:3995031)

Hi bob

The error message you posted does not give us enough info to troubleshoot. Are you able to get any other error messages from your kibana or elasticsearch logs?