# How to access \[0\] element in event array of objects inside of Elasticsearch Script

**URL:** <https://discuss.elastic.co/t/how-to-access-0-element-in-event-array-of-objects-inside-of-elasticsearch-script/132572>\
**Category:** Logstash\
**Created:** [May 19, 2018, 3:47pm UTC](https://discuss.elastic.co/t/how-to-access-0-element-in-event-array-of-objects-inside-of-elasticsearch-script/132572 "2018-05-19T15:47:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hacker\_21](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hacker\_21](https://discuss.elastic.co/u/hacker_21)\
**Post date:** [May 19, 2018, 3:47pm UTC](https://discuss.elastic.co/t/how-to-access-0-element-in-event-array-of-objects-inside-of-elasticsearch-script/132572/1 "2018-05-19T15:47:43Z")

</div>

I have an event created like so:  
`event.set("postal_codes", [{"zip" => event.get("zip"), "city" => event.get("city"), "state" => event.get("state"), "country" => event.get("country"), "freq" => event.get("freq"), "location" => {"lat" => event.get("lat"), "lon" => event.get("lon")}}])`

... it is an array of objects created with the ruby filter plugin.

inside of an Elasticsearch Script for an update, how can I access it's 0th element? The below script simply returns null:  
script =\> ' ctx.\_source.postal\_codes.add(params.event.get("[postal\_codes][0]"));'

any ideas?

---

<div class="post-metadata">

**Author:** ![hacker\_21](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hacker\_21](https://discuss.elastic.co/u/hacker_21)\
**Post date:** [May 21, 2018, 6:35pm UTC](https://discuss.elastic.co/t/how-to-access-0-element-in-event-array-of-objects-inside-of-elasticsearch-script/132572/2 "2018-05-21T18:35:24Z")

</div>

any thoughts ?

---

<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:** [June 18, 2018, 6:35pm UTC](https://discuss.elastic.co/t/how-to-access-0-element-in-event-array-of-objects-inside-of-elasticsearch-script/132572/3 "2018-06-18T18:35:25Z")

</div>

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