# Should i use emit() when using runtime field

**URL:** <https://discuss.elastic.co/t/should-i-use-emit-when-using-runtime-field/317861>\
**Category:** Kibana\
**Created:** [November 1, 2022, 3:49am UTC](https://discuss.elastic.co/t/should-i-use-emit-when-using-runtime-field/317861 "2022-11-01T03:49:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikhatanu](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@mikhatanu](https://discuss.elastic.co/u/mikhatanu)\
**Post date:** [November 1, 2022, 3:49am UTC](https://discuss.elastic.co/t/should-i-use-emit-when-using-runtime-field/317861/1 "2022-11-01T03:49:40Z")

</div>

Hello, i'm trying to sum 2 fields in index template using runtime field. Currently, my script is like this: `doc['a'].value + doc['b'].value`. Do i need to emit like this: `emit(doc['a'].value + doc['b'].value)` so that the new field gets populated with the sum of a and b or is it enough without emit?

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [November 1, 2022, 9:42am UTC](https://discuss.elastic.co/t/should-i-use-emit-when-using-runtime-field/317861/2 "2022-11-01T09:42:00Z")

</div>

You will need to use emit to return the values. There's more detail [here](https://www.elastic.co/guide/en/elasticsearch/painless/8.4/painless-runtime-fields.html) on painless runtime fields if that helps.

---

<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:** [November 29, 2022, 9:42am UTC](https://discuss.elastic.co/t/should-i-use-emit-when-using-runtime-field/317861/3 "2022-11-29T09:42:13Z")

</div>

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