Can I solve one search request whith multi Groovy scripting file?

Like the database functions .. we can use the function like to_number(to_char(...)) , but the function is not fixed.

now we defined the function :
"def abs(data) {return Math.abs(data);};";
"def upper(data){if(data!=null){return data.toUpperCase();}else{return null}};";

and use it in script , inline this
"script":"def abs(data) {return Math.abs(data);};def upper(data){if(data!=null){return data.toUpperCase();}else{return null}};upper(abs(doc['fieild'].value))"

so this way can make memory leak? (Es 2.3.4)

if use script file ,how can i do it ..