How to divide value by 1024 in scripted field

Hi Guys,

Can you help me, I'm trying to divide the field value to 1024 but it showed script invalid.

Below are my codes, I'm using the scripted field.

if(doc['webpage_size'].value !=null) {
return doc['webpage_size'].value / 1024 +'MB';
}
return "";

Can help me to get the output.

1 Like

Hello,

Your script seems to work for me. Did you set the scripted field type to "string"?

Yes, but it didn't work. no any data have been shown.

Can you show me how a document looks like in your dataset?

And I got this once I turned to Discover, no any data was shown. Everything is fine before made that scripted field.

If you remove the created scripted field, can you see any documents in Discover? It is possible that you don't have any documents in the selected time range (Last 15 minutes).

Yes, saw data once I removed the created scripted field. Looks its a bug in 6.4

Nah, it's because it got some error in the scripted field. You could see the toast message in the bottom right of the screen that was something like "X out of Y shards failed". We have to debug your scripted field and figure out why it isn't working. Now that you have the documents in Discover, can you show me a sample document to try and see why the field isn't working?

PS: you can also preview scripted field results in Kibana 6.4 by clicking on the "Get help with the syntax ..." link near the bottom:

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