Painless scrip error in kibana

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 []"
    }
   }
  }
 ]
}

any update on above question.

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\"}

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