I currently have the following painless script:
def m = /^(/[^/?&]+).+/.matcher(doc['request_uri.keyword'].value); if ( m.matches() ) { return m.group(1) } else { return "" }
This works just fine, as long as request_uri.keyword exists. And fails horribly when it doesn't exist.
I tried stuff like:
if (doc['request_uri.keyword'] != null) { def m = /^(/[^/?&]+).+/.matcher(doc['request_uri.keyword'].value); if ( m.matches() ) { return m.group(1) } else { return "" } }
But that doesn't appear to be helping either (various other variants won't even compile).
What would be the proper way to check if a field actually exists? This is on ES5.5 btw.