# Gives error when creating scripted field using nested json

**URL:** <https://discuss.elastic.co/t/gives-error-when-creating-scripted-field-using-nested-json/92116>\
**Category:** Kibana\
**Created:** [July 6, 2017, 1:55pm UTC](https://discuss.elastic.co/t/gives-error-when-creating-scripted-field-using-nested-json/92116 "2017-07-06T13:55:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aman\_yadav](https://avatars.discourse-cdn.com/v4/letter/a/76d3ee/32.png) [@aman\_yadav](https://discuss.elastic.co/u/aman_yadav)\
**Post date:** [July 6, 2017, 1:55pm UTC](https://discuss.elastic.co/t/gives-error-when-creating-scripted-field-using-nested-json/92116/1 "2017-07-06T13:55:13Z")

</div>

I am trying to fetch email address from the logs. changesets.values is an array and it can be empty so taht is why i am using conditional statement. Code below gives error.

doc['changesets.values[0].toCommit.author.emailAddress'].empty ? "default" : doc['changesets.values[0].toCommit.author.emailAddress'].value

---

<div class="post-metadata">

**Author:** ![aman\_yadav](https://avatars.discourse-cdn.com/v4/letter/a/76d3ee/32.png) [@aman\_yadav](https://discuss.elastic.co/u/aman_yadav)\
**Post date:** [July 6, 2017, 7:53pm UTC](https://discuss.elastic.co/t/gives-error-when-creating-scripted-field-using-nested-json/92116/2 "2017-07-06T19:53:01Z")

</div>

Extracted fields in logstash, that worked.

---

<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:** [August 3, 2017, 7:53pm UTC](https://discuss.elastic.co/t/gives-error-when-creating-scripted-field-using-nested-json/92116/3 "2017-08-03T19:53:05Z")

</div>

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