# Painless scrip error in kibana

**URL:** https://discuss.elastic.co/t/painless-scrip-error-in-kibana/227526
**Category:** Elasticsearch
**Created:** [April 10, 2020, 3:22pm UTC](https://discuss.elastic.co/t/painless-scrip-error-in-kibana/227526 "2020-04-10T15:22:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)
#### Post date: [April 10, 2020, 3:22pm UTC](https://discuss.elastic.co/t/painless-scrip-error-in-kibana/227526/1 "2020-04-10T15:22:21Z")

</div>

HI Team,  
I'm working on scripted field to generate userid value in separate field and please find my error detail with script.

Script:

```
def m = /.*UserID/.matcher(doc['message.keyword'].value);
if ( m.matches() ) {
   return m.group(1)
} else {
   return "no match"
}

```

Message:

`message.keyword: 2020-03-12 12:25:21:692 Logger - Received JSON Response: UserID: 124345`

Error:

```
{
 "root_cause": [
  {
   "type": "script_exception",
   "reason": "runtime error",
   "script_stack": [
    "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:94)",
    "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:41)",
    "m = /.*UserID/.matcher(doc['message.keyword'].value);\r\n",
    " ^---- HERE"
   ],
   "script": "def m = /.*UserID/.matcher(doc['message.keyword'].value);\r\nif ( m.matches() ) {\r\n return m.group(1)\r\n} else {\r\n return \"no match\"\r\n}",
   "lang": "painless"
  }
 ],
 "type": "search_phase_execution_exception",
 "reason": "all shards failed",
 "phase": "query",
 "grouped": true,
 "failed_shards": [
  {
   "shard": 0,
   "index": "test",
   "node": "4QB1XVnuRzCkQ7KtGC4r9Q",
   "reason": {
    "type": "script_exception",
    "reason": "runtime error",
    "script_stack": [
     "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:94)",
     "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:41)",
     "m = /.*UserID/.matcher(doc['message.keyword'].value);\r\n",
     " ^---- HERE"
    ],
    "script": "def m = /.*UserID/.matcher(doc['message.keyword'].value);\r\nif ( m.matches() ) {\r\n return m.group(1)\r\n} else {\r\n return \"no match\"\r\n}",
    "lang": "painless",
    "caused_by": {
     "type": "illegal_argument_exception",
     "reason": "No field found for [message.keyword] in mapping with types []"
    }
   }
  }
 ]
}
```

---

<div class="post-metadata">

### Author: ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)
#### Post date: [April 17, 2020, 12:44pm UTC](https://discuss.elastic.co/t/painless-scrip-error-in-kibana/227526/2 "2020-04-17T12:44:22Z")

</div>

any update on above question.

---

<div class="post-metadata">

### Author: ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)
#### Post date: [May 4, 2020, 7:56am UTC](https://discuss.elastic.co/t/painless-scrip-error-in-kibana/227526/3 "2020-05-04T07:56:58Z")

</div>

Finally i cracked my issue and and please find my below solution ,

`if (doc[\"data.keyword\"].value != null){ def m = /UserID: ([0-9]+)/.matcher(doc[\"data.keyword\"].value); if (m.find ()) { return m.group (1) } else { return \"no match\" } } else { return \"NULL\"}`

---

<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: [June 1, 2020, 7:57am UTC](https://discuss.elastic.co/t/painless-scrip-error-in-kibana/227526/4 "2020-06-01T07:57:06Z")

</div>

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