OpenSearch script - accessing global variables inside a function

Opensearch scripts are based on Painless as well.

Painless functions are not well documented, but they have been designed to be completely independent of the script body, so anything that the function should work on must be passed as parameters.

def getPrice(Map document) {
    return document["price"];    
}

int price = getPrice(doc);