# Use a logstash plugin within iteration

**URL:** https://discuss.elastic.co/t/use-a-logstash-plugin-within-iteration/252159
**Category:** Logstash
**Created:** [October 15, 2020, 9:21am UTC](https://discuss.elastic.co/t/use-a-logstash-plugin-within-iteration/252159 "2020-10-15T09:21:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![parosio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parosio/32/27367_2.png) [@parosio](https://discuss.elastic.co/u/parosio)
#### Post date: [October 15, 2020, 9:21am UTC](https://discuss.elastic.co/t/use-a-logstash-plugin-within-iteration/252159/1 "2020-10-15T09:21:59Z")

</div>

Hello,  
I've got documents where a field might contain multiple values.  
All the values from that field have to be looked up in a different index, to get the document enriched.

`"countries" : "India|Congo|Italy"`

I should iterate over the _n_ values and invoke the elastic plugin for each value:

```auto
      mutate {
         split => { "countries" => "|" }
      }
      
      ## sort of foreach country in countries
      elasticsearch {
         hosts => ["es-server"]
         index => "geo_data"
         query_template => "countryToContinent.json"
         fields => { 
            "Continent" => "continents[]"
            "OfficialCountryName" => "country_official_names[]"
         }
      } 

```

countryToContinent.json:

```auto
    {
      "size": 1,
      "_source": ["Continent", "OfficialCountryName"],
      "query": {
        "query_string": {
          "query": ***"%{countries[i]}"***
        }
      }
    }

```

I'm missing how to iterate over countries array and invoke the elasticsearch plugin (but an example with any other plugin would be useful) for each value.  
Additionally, also `continents` and `country_official_names` should end up being array fields.

I've seen [How to loop through array in Logstash](https://discuss.elastic.co/t/how-to-loop-through-array-in-logstash/213852) post and solution, but it doesn't really help me.

Any other suggestion to tackle the problem is welcome.

---

<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: [November 12, 2020, 9:22am UTC](https://discuss.elastic.co/t/use-a-logstash-plugin-within-iteration/252159/2 "2020-11-12T09:22:15Z")

</div>

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