Kibana scripted field (bad request error)

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

return doc['sequence'].value % 2

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"

Below are the full error descriptions

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. [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)

This is the said scripted field

And this is some of the preview results. They're correct as well.

It seems that not every log has the same field. I have added a condition to check whether there is that field and this is solved.

Hey @thanirin,

I have the same problems. Could you tell me exactly what the condition is?

Thanks a lot.

Hi @Anton91,

In my case, every log has the same field called "type", and I also know that a certain type has the field no other type has. That's why I could add a condition to filter the type I want first. For example...

if(doc['type.keyword'].value.contains("the_Type_I_Want")) {
    return doc['filed_not_avail_every_type'].value % 2
}

However, if you don't have a field that can differentiate the log, you might be able check if the interested field is null or not. Although, I'm not sure if it will work because I haven't tried it.


edit: I found out that you can use _exists_:the_field_name to check if a field is not null.

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