# Using field script with Painless and Regex

**URL:** <https://discuss.elastic.co/t/using-field-script-with-painless-and-regex/192077>\
**Category:** Kibana\
**Created:** [July 24, 2019, 3:33pm UTC](https://discuss.elastic.co/t/using-field-script-with-painless-and-regex/192077 "2019-07-24T15:33:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tatitozzo](https://avatars.discourse-cdn.com/v4/letter/t/45deac/32.png) [@tatitozzo](https://discuss.elastic.co/u/tatitozzo)\
**Post date:** [July 24, 2019, 3:33pm UTC](https://discuss.elastic.co/t/using-field-script-with-painless-and-regex/192077/1 "2019-07-24T15:33:36Z")

</div>

Hello,  
I am trying to use painless field script to check if the content of a field has only numeric values, but the script is showing error.  
Elasticsearch is set script.painless.regex.enabled: true.  
I tried to use it as follows:

```
if (doc['tamanho.keyword'].size() != 0) {
    if (doc['tamanho.keyword'].value ==~ /[0-9]/ ) {
        return doc['tamanho.keyword'].value
    } else {
        return 0
    }    
} else {
    return 0
}

```

I am getting the following error:

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

And:

```
if (doc['tamanho.keyword'].size() != 0) {
def m =/[0-9]/.matcher(doc['tamanho.keyword'].value);
if (m.matches() ) {
return m.group(1)
}else{
return 0
}    
}else{
return 0
}

```

I am getting the following error:

![erro2](https://us1.discourse-cdn.com/elastic/original/3X/6/b/6b57f336f116f5a64e060bcca9ef2c2682e14bac.png)

---

<div class="post-metadata">

**Author:** ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)\
**Post date:** [July 24, 2019, 9:16pm UTC](https://discuss.elastic.co/t/using-field-script-with-painless-and-regex/192077/2 "2019-07-24T21:16:19Z")

</div>

@tatitozzo can you please include the full error output that you're seeing?

---

<div class="post-metadata">

**Author:** ![tatitozzo](https://avatars.discourse-cdn.com/v4/letter/t/45deac/32.png) [@tatitozzo](https://discuss.elastic.co/u/tatitozzo)\
**Post date:** [July 25, 2019, 10:40am UTC](https://discuss.elastic.co/t/using-field-script-with-painless-and-regex/192077/3 "2019-07-25T10:40:27Z")

</div>

Hi Brandon!

 ![erro4](https://us1.discourse-cdn.com/elastic/original/3X/7/7/77a83bf07390812e8b35a5048f905bd2d335a2ef.png)

Thanks

---

<div class="post-metadata">

**Author:** ![Brandon\_Kobel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_kobel/32/14829_2.png) [@Brandon\_Kobel](https://discuss.elastic.co/u/Brandon_Kobel)\
**Post date:** [July 25, 2019, 3:20pm UTC](https://discuss.elastic.co/t/using-field-script-with-painless-and-regex/192077/4 "2019-07-25T15:20:13Z")

</div>

Part of the error output is still being cut-off in the screenshot that you posted.

---

<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:** [August 22, 2019, 3:20pm UTC](https://discuss.elastic.co/t/using-field-script-with-painless-and-regex/192077/5 "2019-08-22T15:20:16Z")

</div>

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