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.

$json->aggs->posts->terms=array("field"=>"postid","lang"=>"python","params"=>array("v"=>"doc["postid"].value"),"script"=>"v");

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