I'm attempted to create a scripted field that grabs the value of a field, strips off text that matches the regex, and then puts the modified value in a new field. I am using a modified example from the documentation because I don't know the language to create it myself.
ctx._source['Full URL'] = /https:\/\/example\.com\/government\/elections\//.matcher(ctx._source['Full URL']).replaceAll('')
When I preview the script, it doesn't throw errors but I also don't get any preview results. When I create the scripted field, it appears to be successful and appears in the index pattern list. Unfortunately, after that the Discover section does not show any results over any time period and Kibana says 1 of 2 shards failed (I run a single node, single shard configuration).
If I attempt to create a visualization, targeting the new field, I get the below error:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source['Full URL'] == /https:\\/\\/example\\.com\\/government\\/elections\\//i.matcher(ctx._source['Full URL']).replaceAll('')",
" ^---- HERE"
],
"script": "ctx._source['Full URL'] == /https:\\/\\/example\\.com\\/government\\/elections\\//i.matcher(ctx._source['Full URL']).replaceAll('')",
"lang": "painless"
},
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source['Full URL'] == /https:\\/\\/example\\.com\\/government\\/elections\\//i.matcher(ctx._source['Full URL']).replaceAll('')",
" ^---- HERE"
],
"script": "ctx._source['Full URL'] == /https:\\/\\/example\\.com\\/government\\/elections\\//i.matcher(ctx._source['Full URL']).replaceAll('')",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "cloudflare-2018.10.30",
"node": "pPGsP09BSNeNANYO6A9KEQ",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source['Full URL'] == /https:\\/\\/example\\.com\\/government\\/elections\\//i.matcher(ctx._source['Full URL']).replaceAll('')",
" ^---- HERE"
],
"script": "ctx._source['Full URL'] == /https:\\/\\/example\\.com\\/government\\/elections\\//i.matcher(ctx._source['Full URL']).replaceAll('')",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
},
{
"shard": 0,
"index": "cloudflare-2018.10.31",
"node": "pPGsP09BSNeNANYO6A9KEQ",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source['Full URL'] == /https:\\/\\/example\\.com\\/government\\/elections\\//i.matcher(ctx._source['Full URL']).replaceAll('')",
" ^---- HERE"
],
"script": "ctx._source['Full URL'] == /https:\\/\\/example\\.com\\/government\\/elections\\//i.matcher(ctx._source['Full URL']).replaceAll('')",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
}
]
},
"status": 500
}