Hi,
we had a bug in our documentation, please check the docs again for an example.
Instead of script_fields
use script
together with an aggregation.
It seems you run into the same issue as the user in this thread. Please check his last post for the solution.