# Parse Array and Send to Elastic Filter

**URL:** https://discuss.elastic.co/t/parse-array-and-send-to-elastic-filter/306271
**Category:** Logstash
**Created:** [June 2, 2022, 8:39pm UTC](https://discuss.elastic.co/t/parse-array-and-send-to-elastic-filter/306271 "2022-06-02T20:39:26Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JeremyP](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@JeremyP](https://discuss.elastic.co/u/JeremyP)
#### Post date: [June 2, 2022, 8:39pm UTC](https://discuss.elastic.co/t/parse-array-and-send-to-elastic-filter/306271/1 "2022-06-02T20:39:26Z")

</div>

Hello,

I have an array of strings which I'd like to send nested object to an Elasticsearch filter to obtain additional data in a separately stored index. I've been searching for an approach to this but I cannot seem to find an example. I'm comfortable with creating the Elasticsearch filter, but I'm trying to determine a way to pull out each value from the array to send to the filter. I've looked at a Ruby filter, but I don't see how I can create the ES filter within that block of code.

Here is my sample data...

```auto

      "categories": [
        "Red Hat",
        "Red Hat Enterprise Linux",
        "Remote Execution"
     ]

```

Each category individually gets sent to the ES filter.

Thank you for any guidance you can offer.

---

<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: [June 2, 2022, 9:00pm UTC](https://discuss.elastic.co/t/parse-array-and-send-to-elastic-filter/306271/2 "2022-06-02T21:00:52Z")

</div>

Perhaps use a [split](https://www.elastic.co/guide/en/logstash/current/plugins-filters-split.html) filter, so that instead of an event with an array you have three events in which [categories] is a string. It is really not clear what you want to do.

If there is a limit to the number of categories then you might also be able to do

```
if [categories][0] { elasticsearch { query => "someField: %{[categories][0]}" ... } }
if [categories][1] { elasticsearch { query => "someField: %{[categories][1]}" ... } }
if [categories][2] { elasticsearch { query => "someField: %{[categories][2]}" ... } }
if [categories][3] { elasticsearch { query => "someField: %{[categories][3]}" ... } }
```

---

<div class="post-metadata">

### Author: ![JeremyP](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@JeremyP](https://discuss.elastic.co/u/JeremyP)
#### Post date: [June 3, 2022, 12:54pm UTC](https://discuss.elastic.co/t/parse-array-and-send-to-elastic-filter/306271/3 "2022-06-03T12:54:23Z")

</div>

This is exactly what I wanted. I wasn't sure if there were a better method to parse through the array vs having to define each array position. There should only be about 5 or 6 categories.

---

<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: [July 1, 2022, 12:54pm UTC](https://discuss.elastic.co/t/parse-array-and-send-to-elastic-filter/306271/4 "2022-07-01T12:54:44Z")

</div>

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