# Create fields from the objects that are a part of array in Logstash filter

**URL:** <https://discuss.elastic.co/t/create-fields-from-the-objects-that-are-a-part-of-array-in-logstash-filter/299088>\
**Category:** Logstash\
**Created:** [March 8, 2022, 12:21pm UTC](https://discuss.elastic.co/t/create-fields-from-the-objects-that-are-a-part-of-array-in-logstash-filter/299088 "2022-03-08T12:21:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Usman18](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@Usman18](https://discuss.elastic.co/u/Usman18)\
**Post date:** [March 8, 2022, 12:21pm UTC](https://discuss.elastic.co/t/create-fields-from-the-objects-that-are-a-part-of-array-in-logstash-filter/299088/1 "2022-03-08T12:21:09Z")

</div>

In Logstash, in my event object there is a field that is an array. This field contains objects. I have to create or add some new fields in the event object and these fields will be created on the basis of the objects that are present in this array field.  
For example, suppose I have the below field in my event object:

```auto
{
  "data_items": [
    {
      {
        "unit": "bytes",
        "value": 752
      },
      {
        "unit": "ms",
        "value": 15
      }
    }
  ]
}

```

Now, I want to create 2 new fields for these 2 objects that are present in the data\_items field and they will be assigned the value from the "value" field of the corresponding object in the array. For example, I have to add these fields in my event object:

```auto
field_bytes:752,
field_ms: 15

```

My question is that is there any easy way to do this? The order of the objects in the array is random. I know that using if statements and add\_field options I can achieve this but is there any easy way to do this. Thanks

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 8, 2022, 5:14pm UTC](https://discuss.elastic.co/t/create-fields-from-the-objects-that-are-a-part-of-array-in-logstash-filter/299088/2 "2022-03-08T17:14:43Z")

</div>

You could use a ruby filter like [this](https://discuss.elastic.co/t/how-can-i-flatten-an-array-in-my-document/235807/3). Note the correction to that post in the final post of the thread.

---

<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:** [April 5, 2022, 5:15pm UTC](https://discuss.elastic.co/t/create-fields-from-the-objects-that-are-a-part-of-array-in-logstash-filter/299088/3 "2022-04-05T17:15:36Z")

</div>

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