# Script field aggregation

**URL:** <https://discuss.elastic.co/t/script-field-aggregation/37710>\
**Category:** Elasticsearch\
**Created:** [December 21, 2015, 6:00pm UTC](https://discuss.elastic.co/t/script-field-aggregation/37710 "2015-12-21T18:00:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pawel\_Rog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_rog/32/141223_2.png) [@Pawel\_Rog](https://discuss.elastic.co/u/Pawel_Rog)\
**Post date:** [December 21, 2015, 6:00pm UTC](https://discuss.elastic.co/t/script-field-aggregation/37710/1 "2015-12-21T18:00:17Z")

</div>

I cannot find any information about this so I'm posting this topic. Is it possible to run terms, sum or avg aggregations on field which was created using script\_fields feature?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [December 21, 2015, 9:45pm UTC](https://discuss.elastic.co/t/script-field-aggregation/37710/2 "2015-12-21T21:45:12Z")

</div>

Elasticsearch supports running aggregations on scripts, but beware that it has a significant performance impact, not only because scripts make things slow, but also because some optimizations are not available anymore (eg. ordinals on strings).

[https://www.elastic.co/guide/en/elasticsearch/reference/2.1/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-script](https://www.elastic.co/guide/en/elasticsearch/reference/2.1/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-script)

---

<div class="post-metadata">

**Author:** ![Pawel\_Rog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_rog/32/141223_2.png) [@Pawel\_Rog](https://discuss.elastic.co/u/Pawel_Rog)\
**Post date:** [December 21, 2015, 9:57pm UTC](https://discuss.elastic.co/t/script-field-aggregation/37710/3 "2015-12-21T21:57:28Z")

</div>

Thank you for information Adrien.

---

<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 5, 2017, 11:29pm UTC](https://discuss.elastic.co/t/script-field-aggregation/37710/4 "2017-07-05T23:29:28Z")

</div>


