Python Script for Aggregation

I'm writing a custom script for aggregations, but I don't know how to pass the value of the aggregated field to the script.

I've tried "_value", "doc['field'].value", but it goes to the script as a constant.


In the python script, variable "v" should have the value of the field "postid" that is being aggregated.