How to divide value by 1024 in scripted field


(Mr.M) #1

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.


(Marius Dragomir) #2

Hello,

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


(Mr.M) #3

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


(Marius Dragomir) #4

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


(Mr.M) #5

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


(Marius Dragomir) #6

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


(Mr.M) #7

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


(Marius Dragomir) #8

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:


(system) #9

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