# Scripted nested sum aggregation with root attribute

**URL:** <https://discuss.elastic.co/t/scripted-nested-sum-aggregation-with-root-attribute/177060>\
**Category:** Elasticsearch\
**Created:** [April 16, 2019, 10:36am UTC](https://discuss.elastic.co/t/scripted-nested-sum-aggregation-with-root-attribute/177060 "2019-04-16T10:36:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Istvan\_Ignacz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/istvan_ignacz/32/44235_2.png) [@Istvan\_Ignacz](https://discuss.elastic.co/u/Istvan_Ignacz)\
**Post date:** [April 16, 2019, 10:36am UTC](https://discuss.elastic.co/t/scripted-nested-sum-aggregation-with-root-attribute/177060/1 "2019-04-16T10:36:24Z")

</div>

Hello,

I'm facing the same issue as this one (already closed): [Scripted nested sum aggregation with top document field](https://discuss.elastic.co/t/scripted-nested-sum-aggregation-with-top-document-field/25326)

In an existing index in an elasticsearch 5.6 cluster I have a numeric value and another in a nested document. I'd like to create a scripted sum like this: {"script":"doc['nested.someNumber'] \* doc['rootNumber']"}

As far as I know, "include\_in\_root" property is deprecated since the post was closed and could not find any documentation about this field.

Is the only way to achieve this currently is to create a new field in the nested doc and use "copy\_to" in the root doc?

Thanks!

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [April 19, 2019, 7:02pm UTC](https://discuss.elastic.co/t/scripted-nested-sum-aggregation-with-root-attribute/177060/2 "2019-04-19T19:02:26Z")

</div>

Yes, if you want to access a value in a script for each nested doc, you will need that value in the nested doc directly.

---

<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:** [May 17, 2019, 7:07pm UTC](https://discuss.elastic.co/t/scripted-nested-sum-aggregation-with-root-attribute/177060/3 "2019-05-17T19:07:51Z")

</div>

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