# Painless Sum aggregation with scripted field

**URL:** <https://discuss.elastic.co/t/painless-sum-aggregation-with-scripted-field/119210>\
**Category:** Kibana\
**Created:** [February 9, 2018, 10:16am UTC](https://discuss.elastic.co/t/painless-sum-aggregation-with-scripted-field/119210 "2018-02-09T10:16:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wills1](https://avatars.discourse-cdn.com/v4/letter/w/85e7bf/32.png) [@Wills1](https://discuss.elastic.co/u/Wills1)\
**Post date:** [February 9, 2018, 10:16am UTC](https://discuss.elastic.co/t/painless-sum-aggregation-with-scripted-field/119210/1 "2018-02-09T10:16:09Z")

</div>

Hi !  
I have a question relative to scripted field in Kibana.  
It is possible to summe all the values of a field in painless with scripted field ?  
Something like: SUM(doc.['somefield'].value) ?

---

<div class="post-metadata">

**Author:** ![cjcenizal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjcenizal/32/11216_2.png) [@cjcenizal](https://discuss.elastic.co/u/cjcenizal)\
**Post date:** [February 9, 2018, 6:42pm UTC](https://discuss.elastic.co/t/painless-sum-aggregation-with-scripted-field/119210/2 "2018-02-09T18:42:07Z")

</div>

Hi there, scripted fields only operate on the individual document, and not across all documents. In other words, they don't execute queries themselves. Rather they're intended to be used within queries. So you could execute a query which sums the value of this scripted field across all documents, e.g. in Visualize or in Console. Take a look at the documentation for [sum aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html) for more info. Does this help?

CJ

---

<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:** [March 9, 2018, 6:42pm UTC](https://discuss.elastic.co/t/painless-sum-aggregation-with-scripted-field/119210/3 "2018-03-09T18:42:14Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
