ElasticSearch: access document nested value in groovy script
Use _source for nested properties. Doc holds fields that are loaded in memory. Nested documents may not be loaded and should be accessed with _source.
For instance:
GET index/type { "aggs": { "NAME": { "scripted_metric": { "init_script": "_agg['collection']=[]", "map_script": "_agg['tr'].add(_source.propertry1.prop);", "combine_script": "return _agg", "reduce_script": "return _aggs" } } }, "size": 0}