Scripted fields to convert seconds to hours

Cant figure it out, need an additional field that will convert seconds into hours

I have a number field called Session-Time which i need converting into hours and displayed in another field. I have tried to create a scripted field with the following painless lines but keeps saying error in script



doc['Session-Time'].value / 3600

the preview just says error in script and then points to the dot in .value

Try adding the word return prior to:

return doc['Session-Time'].value / 3600

Also, another option would be to add a scripted field that is just:

return doc['Session-Time'].value

And then using Kibana's input and output formats to convert the number from hours to seconds.

thanks, I did try the return at the beginning but still same error.

forgot to mention the Session-Time is now always populated with a value, so does this mean i have to add an If statement in to check if the fields is populated before performing the math

just seen in the preview more detail re: the error "a document doesn't have a value for a field..."

Ah, yes, I would try adding an if statement if the value at one point was not always populated.


if (!doc['Session-Time'].empty) {

fantastic, that worked

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