# Script field not returning value

**URL:** https://discuss.elastic.co/t/script-field-not-returning-value/255549
**Category:** Kibana
**Created:** [November 16, 2020, 1:55pm UTC](https://discuss.elastic.co/t/script-field-not-returning-value/255549 "2020-11-16T13:55:44Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![pmo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmo/32/79080_2.png) [@pmo](https://discuss.elastic.co/u/pmo)
#### Post date: [November 16, 2020, 1:55pm UTC](https://discuss.elastic.co/t/script-field-not-returning-value/255549/1 "2020-11-16T13:55:44Z")

</div>

Hi support,  
I've created this Script Field in Kibana index pattern, but I've an issue, nothing is return...  
Each time I have a field name : category\_name that match "Router", I should have a value (netflow value), But I always have null !

What I do wrong ?

Regards,  
Philippe

```auto
double netflow = 15.22;
if (doc['category_name'].size() == 0) {
    return null;
} else { 
    if (doc['category_name'].value == 'Router') {
    return netflow;
    }
}

```

---

<div class="post-metadata">

### Author: ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)
#### Post date: [November 16, 2020, 3:52pm UTC](https://discuss.elastic.co/t/script-field-not-returning-value/255549/2 "2020-11-16T15:52:10Z")

</div>

Can you share an example document and the mapping of your index?

---

<div class="post-metadata">

### Author: ![pmo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmo/32/79080_2.png) [@pmo](https://discuss.elastic.co/u/pmo)
#### Post date: [November 16, 2020, 4:00pm UTC](https://discuss.elastic.co/t/script-field-not-returning-value/255549/3 "2020-11-16T16:00:55Z")

</div>

@flash1293

You put your finger exactly on the good things !

```auto
"category_name": {
          "type": "keyword",
          "normalizer": "uppercase"
        },

```

I 've to put my value to "ROUTER" and not "Router" cause of the normalizer that we added. 😉

Thanks a lot.

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [November 16, 2020, 4:07pm UTC](https://discuss.elastic.co/t/script-field-not-returning-value/255549/4 "2020-11-16T16:07:05Z")

</div>

Change `.size()` to `.length()`

```auto
double netflow = 15.22;
if (doc['category_name'].length() == 0) {
    return null;
} else { 
    if (doc['category_name'].value == 'Router') {
    return netflow;
    }
}

```

---

<div class="post-metadata">

### Author: ![pmo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmo/32/79080_2.png) [@pmo](https://discuss.elastic.co/u/pmo)
#### Post date: [November 16, 2020, 4:11pm UTC](https://discuss.elastic.co/t/script-field-not-returning-value/255549/5 "2020-11-16T16:11:48Z")

</div>

@aaron-nimocks @flash1293  
The issue was the normalizer and so the case of the value that was uppercase.  
It's working now with my code below.  
I didn't change the .size to .length  
but may be it's because I always have something ? Do you think my code is not working well and have to change it ?  
Thanks a lot for your help

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [November 16, 2020, 4:15pm UTC](https://discuss.elastic.co/t/script-field-not-returning-value/255549/6 "2020-11-16T16:15:15Z")

</div>

Size didn't work for me but I was defining my own variables and I think size() works for arrays. If it works for you, great.

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

Length did work.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/d/fd155d8256104a19928369ce13606a4c06d8259b.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: [December 14, 2020, 4:15pm UTC](https://discuss.elastic.co/t/script-field-not-returning-value/255549/7 "2020-12-14T16:15:20Z")

</div>

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