Hi there,
I collect data from ntopng in Elasticsearch
I have a "HTTP_HOST.keyword" field that contains the FQDN
I need to create a field containing only the domain name of the first and second level
Regex: [^.] + . [^.] + $
For example:
7.tlu.dl.delivery.mp.microsoft.com -> microsoft.com
I created the script, as described in the example
Match a string and return that match
def m = /[^.]+.[^.]+$/.matcher(doc['HTTP_HOST.keyword'].value);
if (m.matches ()) {
return m.group (1)
} else {
return "no match"
}
But I get the error:
Error: Request to Elasticsearch failed: {"error": {"root_cause": [{"type": "script_exception", "reason": "runtime error", "script_stack": ["java.util.regex.Matcher. getTextLength (Matcher.java:1283) "," java.util.regex.Matcher.reset (Matcher.java:309) "," java.util.regex.Matcher. (Matcher.java:229) ", "java.util.regex.Pattern.matcher (Pattern.java:1093)", "m = /[^.]+\.[^.]+$/.matcher(doc['HTTP_HOST.keyword ']. value); \ n "," ^ ---- HERE "]," script ":" def m = /[^.]+\.[^.]+$/.matcher(doc['HTTP_HOST.keyword '] .value); \ nif (m.matches ()) {\ n return m.group (1) \ n} else {\ n return \ "no match " \ n} "," lang ":" painless "}," type ":" search_phase_execution_exception "," reason ":" all shards failed "," phase ":" query "," grouped ": true," failed_shards ": [{" shard ": 0," index ":" ntopng-2018.01.18 "," node ":" lHy542BoQ1-7g6ifEFLHcw "," reason ": {" type ":" script_exception "," reason ":" runtime error "," script_stack ": [" java. util.regex.Matcher.getTextLength (Matcher.java:1283) "," java.util.regex.Ma tcher.reset (Matcher.java:309) "," java.util.regex.Matcher. (Matcher.java:229) "," java.util.regex.Pattern.matcher (Pattern.java:1093) "," m = /[^.]+\.[^.]+$/.matcher(doc['HTTP_HOST.keyword'].value);\n "," ^ ---- HERE "], "script": "def m = /[^.]+\.[^.]+$/.matcher(doc['HTTP_HOST.keyword'].value);\nif (m.matches ()) {\ n return m.group (1) \ n} else {\ n return \ "no match " \ n} "," lang ":" painless "," caused_by ": {" type ":" null_pointer_exception "," reason ": null}}}]}," status ": 500}
What am I doing wrong?