# Does Painless Script can extract text data from fields?

**URL:** <https://discuss.elastic.co/t/does-painless-script-can-extract-text-data-from-fields/216158>\
**Category:** Kibana\
**Created:** [January 23, 2020, 12:27am UTC](https://discuss.elastic.co/t/does-painless-script-can-extract-text-data-from-fields/216158 "2020-01-23T00:27:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Gonzalez1](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@Daniel\_Gonzalez1](https://discuss.elastic.co/u/Daniel_Gonzalez1)\
**Post date:** [January 23, 2020, 12:27am UTC](https://discuss.elastic.co/t/does-painless-script-can-extract-text-data-from-fields/216158/1 "2020-01-23T00:27:31Z")

</div>

Hi!

I'm trying to extract data from a field with Painless Script this is the message from the field.

```
15Jan20 09:31:04.83 PRIFBLOQ MXP1 RACF SETROPTS success for PRIFBLOQ
   Jobname + id: RFJPDDT2
   RACF command: SETROPTS RACLIST(FACILITY) REFRESH
   Name : BLOQUEO Y BAJAS RACF Instdata : U PROC. BAJAS Y BLOQUEOS AUTOM. DE RACF

```

And this is the script that I'm trying to use

```
def m= /RACF\scommand:\s\w+\s\w+\s(?.+)\sName/.matcher(doc['message.keyword'].value);
if (m.matches() ) {

 return m.group(1) 

} else {

return "no match"

}

```

Just for the record I applied to the field message2 the next

```
PUT racf/_mapping
{
  "properties": {
    "message2": { 
      "type": "text",
      "fielddata": true
    }
  }
}

```

But even when the regular expression is correct and I tested in a [rex101.com](http://rex101.com) the Script doesn't recognize the regular expression.

But if I tried with this script

```
    def m= /(.+)/.matcher(doc['message.keyword'].value);
    if (m.matches() ) {

     return m.group(1) 

    } else {

    return "no match"

    }

```

It brings me some random number data of the field message2, so that means that script recognize some regular expression, but when I want to extract text it doesn't work.

What could be wrong?

---

<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:** [January 28, 2020, 4:45pm UTC](https://discuss.elastic.co/t/does-painless-script-can-extract-text-data-from-fields/216158/2 "2020-01-28T16:45:45Z")

</div>

The scripted fields are based on the Java implementation of Regex, which is kinda hard to debug. You can try to achieve the same result by using Java string manipulation functions.

---

<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:** [February 25, 2020, 4:45pm UTC](https://discuss.elastic.co/t/does-painless-script-can-extract-text-data-from-fields/216158/3 "2020-02-25T16:45:56Z")

</div>

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