# How to divide value by 1024 in scripted field

**URL:** <https://discuss.elastic.co/t/how-to-divide-value-by-1024-in-scripted-field/151568>\
**Category:** Kibana\
**Created:** [October 9, 2018, 7:51am UTC](https://discuss.elastic.co/t/how-to-divide-value-by-1024-in-scripted-field/151568 "2018-10-09T07:51:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark.quilates](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark.quilates/32/24802_2.png) [@mark.quilates](https://discuss.elastic.co/u/mark.quilates)\
**Post date:** [October 9, 2018, 7:51am UTC](https://discuss.elastic.co/t/how-to-divide-value-by-1024-in-scripted-field/151568/1 "2018-10-09T07:51:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [October 10, 2018, 10:31am UTC](https://discuss.elastic.co/t/how-to-divide-value-by-1024-in-scripted-field/151568/2 "2018-10-10T10:31:26Z")

</div>

Hello,

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

---

<div class="post-metadata">

**Author:** ![mark.quilates](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark.quilates/32/24802_2.png) [@mark.quilates](https://discuss.elastic.co/u/mark.quilates)\
**Post date:** [October 10, 2018, 10:43am UTC](https://discuss.elastic.co/t/how-to-divide-value-by-1024-in-scripted-field/151568/3 "2018-10-10T10:43:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [October 10, 2018, 10:47am UTC](https://discuss.elastic.co/t/how-to-divide-value-by-1024-in-scripted-field/151568/4 "2018-10-10T10:47:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mark.quilates](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark.quilates/32/24802_2.png) [@mark.quilates](https://discuss.elastic.co/u/mark.quilates)\
**Post date:** [October 10, 2018, 10:57am UTC](https://discuss.elastic.co/t/how-to-divide-value-by-1024-in-scripted-field/151568/5 "2018-10-10T10:57:31Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/b/8/b8d56677e51ba60685a5c01d3a078dc63ddf0a19.png)

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

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/f/0f34b9aa933619e237d59b7670d6c7cd8ea98bf6.png)

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [October 10, 2018, 11:08am UTC](https://discuss.elastic.co/t/how-to-divide-value-by-1024-in-scripted-field/151568/6 "2018-10-10T11:08:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mark.quilates](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark.quilates/32/24802_2.png) [@mark.quilates](https://discuss.elastic.co/u/mark.quilates)\
**Post date:** [October 11, 2018, 2:04am UTC](https://discuss.elastic.co/t/how-to-divide-value-by-1024-in-scripted-field/151568/7 "2018-10-11T02:04:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [October 11, 2018, 9:04am UTC](https://discuss.elastic.co/t/how-to-divide-value-by-1024-in-scripted-field/151568/8 "2018-10-11T09:04:19Z")

</div>

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:

 ![Screenshot%20from%202018-10-11%2012-07-50](https://us1.discourse-cdn.com/elastic/original/3X/b/b/bb24a307eafdb50c989ff793083f27d70a8dd1ae.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 8, 2018, 9:05am UTC](https://discuss.elastic.co/t/how-to-divide-value-by-1024-in-scripted-field/151568/9 "2018-11-08T09:05:01Z")

</div>

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