Scripted field causes discover to fail kibana 7.8

i added a scripted field and after that i can no longer use the discover to search or create filters, on the particular index that i added the field on...

this is what i have in scripted field

if(doc['keywords.sentiment.score'].value == null || doc['keywords.sentiment.score'].value == '' ){ return 0; }else{ return (doc['keywords.sentiment.score'].value * -1); }

and this is the error

Error: Bad Request
at Fetch._callee3$ (http://52.40.99.69:5601/32141/bundles/commons.bundle.js:3:1292397)
at l (http://52.40.99.69:5601/32141/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:288:969217)
at Generator._invoke (http://52.40.99.69:5601/32141/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:288:968970)
at Generator.forEach.e. [as next] (http://52.40.99.69:5601/32141/bundles/kbn-ui-shared-deps/kbn-ui-shared-deps.js:288:969574)
at asyncGeneratorStep (http://52.40.99.69:5601/32141/bundles/commons.bundle.js:3:1285920)
at _next (http://52.40.99.69:5601/32141/bundles/commons.bundle.js:3:1286231)

Computing data on the fly with scripted fields can be very resource intensive and can have a direct impact on Kibana performance. Keep in mind that there’s no built-in validation of a scripted field. If your scripts are buggy, you’ll get exceptions whenever you try to view the dynamically generated data.

Use something like this to check if field exist in the doc

if (!doc.containsKey('myfield') || doc['myfield'].empty) { return "unavailable" } else { return doc['myfield'].value }

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