# Scripted field to convert 1024 Bytes to 1000 metric bytes

**URL:** <https://discuss.elastic.co/t/scripted-field-to-convert-1024-bytes-to-1000-metric-bytes/237901>\
**Category:** Kibana\
**Created:** [June 20, 2020, 7:49am UTC](https://discuss.elastic.co/t/scripted-field-to-convert-1024-bytes-to-1000-metric-bytes/237901 "2020-06-20T07:49:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chowpay](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@chowpay](https://discuss.elastic.co/u/chowpay)\
**Post date:** [June 20, 2020, 7:49am UTC](https://discuss.elastic.co/t/scripted-field-to-convert-1024-bytes-to-1000-metric-bytes/237901/1 "2020-06-20T07:49:47Z")

</div>

In 6.4.2 I have a scripted filed that converts 1024Bytes to 1000Bytes as that is how we bill by this is the script that was working in 6.4.2

```
(doc['total_usage'].value *1000000000) * Math.pow(1.024, Math.floor(Math.log(doc['total_usage'].value*1000000000)/Math.log(1000)))

```

When I try to do this in 7.0.0 I get an error rendering . Just says shards failed  
What is the right way to do this in scripted field for 7.0.0?

Thanks

---

<div class="post-metadata">

**Author:** ![chowpay](https://avatars.discourse-cdn.com/v4/letter/c/ee7513/32.png) [@chowpay](https://discuss.elastic.co/u/chowpay)\
**Post date:** [June 22, 2020, 6:15pm UTC](https://discuss.elastic.co/t/scripted-field-to-convert-1024-bytes-to-1000-metric-bytes/237901/2 "2020-06-22T18:15:28Z")

</div>

Got it working by adding a validator I guess the problem is that the new kibana is strict if the size is 0 it fails where as 6.4.3 will just ignore and process the next value. Here is the working version of the above:

```auto
def output = 0;
List varlist= ['total_usage']; for (s in varlist) { if (doc[s].size()>0) {output = (doc['total_usage'].value *1000000000) * Math.pow(1.024, Math.floor(Math.log(doc['total_usage'].value*1000000000)/Math.log(1000))) }}
return output;

```

---

<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:** [July 20, 2020, 6:15pm UTC](https://discuss.elastic.co/t/scripted-field-to-convert-1024-bytes-to-1000-metric-bytes/237901/3 "2020-07-20T18:15:36Z")

</div>

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