# Create nested field for aggregate plugin output?

**URL:** <https://discuss.elastic.co/t/create-nested-field-for-aggregate-plugin-output/106087>\
**Category:** Logstash\
**Created:** [November 1, 2017, 7:06pm UTC](https://discuss.elastic.co/t/create-nested-field-for-aggregate-plugin-output/106087 "2017-11-01T19:06:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![khommel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/khommel/32/21158_2.png) [@khommel](https://discuss.elastic.co/u/khommel)\
**Post date:** [November 1, 2017, 7:06pm UTC](https://discuss.elastic.co/t/create-nested-field-for-aggregate-plugin-output/106087/1 "2017-11-01T19:06:35Z")

</div>

I'm using the Aggregate plugin to calculate a value. I'm trying to set the value in a nested field, creating the field at the same time. My code is:

code =\> "event.set('[msg][duration]', event.get('[msg][time]') - map['begin'])"

[msg] exists before I call this code, but [msg][duration] does not. The code works, and creates [msg][duration] with an appropriate value. But the plugin raises an exception:

[2017-11-01T18:51:05,757][ERROR][logstash.filters.aggregate] Aggregate exception occurred {:error=\>#\<TypeError: NilClass can't be coerced into Fixnum\>, :code=\>"event.set('[msg][duration]', event.get('[msg][time]') - map['begin'])", :map=\>{}, :event\_data=\>{"msg"=\>{"build\_id"=\>315, "msg\_type"=\>"status", "seq\_id"=\>90, "time"=\>1509562265, "version"=\>1.0, "status"=\>"succeeded"}, ...

What am I doing wrong? Is there a better way to return the calculated value in the intended field?

---

<div class="post-metadata">

**Author:** ![ssasporta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ssasporta/32/13695_2.png) [@ssasporta](https://discuss.elastic.co/u/ssasporta)\
**Post date:** [November 12, 2017, 5:40pm UTC](https://discuss.elastic.co/t/create-nested-field-for-aggregate-plugin-output/106087/2 "2017-11-12T17:40:04Z")

</div>

For me it looks like that the value of : "event.get('[msg][time]') - map['begin']" is null

Check it. Try for example to set an hard coded number.

---

<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:** [December 10, 2017, 5:40pm UTC](https://discuss.elastic.co/t/create-nested-field-for-aggregate-plugin-output/106087/3 "2017-12-10T17:40:09Z")

</div>

Closed on December 10, 2017, 5:40pm UTC

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