# Having trouble converting Groovy to Painless

**URL:** <https://discuss.elastic.co/t/having-trouble-converting-groovy-to-painless/176118>\
**Category:** Elasticsearch\
**Created:** [April 9, 2019, 10:26pm UTC](https://discuss.elastic.co/t/having-trouble-converting-groovy-to-painless/176118 "2019-04-09T22:26:31Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![jw-ovgd](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@jw-ovgd](https://discuss.elastic.co/u/jw-ovgd)\
**Post date:** [April 11, 2019, 7:23pm UTC](https://discuss.elastic.co/t/having-trouble-converting-groovy-to-painless/176118/4 "2019-04-11T19:23:06Z")

</div>

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:

> [@Accessing \_source from script search in 5.0](https://discuss.elastic.co/t/accessing--source-from-script-search-in-5-0/64358):
>
> Hey all, I think I'm going crazy... Could someone tell me why I fail to access the \_source field on this query? { "size": 0, "query": { "constant\_score": { "filter": { "script": { "script": { "inline": "\_source.lab\_tests.length \> 0" } } } } } } I get... { "type": "script\_exception", "reason": "compile error", "caused\_by": { "type": "illegal\_argument\_exception", "reason": "Variable [\_source] is not de…

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.

---

_[View the full topic](https://discuss.elastic.co/t/having-trouble-converting-groovy-to-painless/176118)._
