# Python Script for Aggregation

**URL:** <https://discuss.elastic.co/t/python-script-for-aggregation/258>\
**Category:** Elasticsearch\
**Created:** [May 6, 2015, 6:27am UTC](https://discuss.elastic.co/t/python-script-for-aggregation/258 "2015-05-06T06:27:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkamiche](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkamiche/32/14559_2.png) [@bkamiche](https://discuss.elastic.co/u/bkamiche)\
**Post date:** [May 6, 2015, 6:27am UTC](https://discuss.elastic.co/t/python-script-for-aggregation/258/1 "2015-05-06T06:27:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:15am UTC](https://discuss.elastic.co/t/python-script-for-aggregation/258/2 "2017-07-06T00:15:32Z")

</div>


