Having trouble converting Groovy to Painless

When I try to access params._source I get a null_pointer_exception.

This script is being executed on a search and with Painless.

This discussion:

Makes it seem like I do not have access to _source from a Painless search script. Is that the case?

If that is the case, is what I am trying to do futile? The doc value for my "groups" field seems flattened so I would not be able to traverse the data structure as I need to.