Join GitHub today
NPE when using expression script aggregation in multi level aggregations #26611
Elasticsearch version (
Plugins installed: 
Steps to reproduce:
Note: If the script type were painless, the aggregation works fine.
Provide logs (if relevant):
This issue occurs only when terms aggs are executed in
Although the bug doesn't manifest in 6.0 and later, I think we should apply this fix on master, 6.x and 6.0 branches too.