# How to write while loops inside Logstash Elasticsearch

**URL:** <https://discuss.elastic.co/t/how-to-write-while-loops-inside-logstash-elasticsearch/278805>\
**Category:** Logstash\
**Created:** [July 15, 2021, 2:33pm UTC](https://discuss.elastic.co/t/how-to-write-while-loops-inside-logstash-elasticsearch/278805 "2021-07-15T14:33:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hieu\_Luong](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hieu_luong/32/91689_2.png) [@Hieu\_Luong](https://discuss.elastic.co/u/Hieu_Luong)\
**Post date:** [July 15, 2021, 2:33pm UTC](https://discuss.elastic.co/t/how-to-write-while-loops-inside-logstash-elasticsearch/278805/1 "2021-07-15T14:33:40Z")

</div>

Is there any way to write loops inside output of Logstash

For a certain message

> "total:100 name:product 1"

I can parse `total` from this message and want to send 100 times to elasticsearch My code is just pseudocode, is there any way to implement this?

```auto
filter {
  grok {
    match => { "message" => "%{total:total} (?m)%{name:name}" }
  }
}
output {
    while count<=time do
      elasticsearch { 
          hosts => ["localhost:9200"]
          index => "data-test"
          user => "elastic"
          password => "changeme"
      }
    end
}

```

---

<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:** [July 15, 2021, 3:59pm UTC](https://discuss.elastic.co/t/how-to-write-while-loops-inside-logstash-elasticsearch/278805/2 "2021-07-15T15:59:18Z")

</div>

No you cannot implement a loop in the output section. If you want 100 copies of something you could use a ruby filter to add 100 copies of it to an array, then use a split filter to make each one a separate event.

---

<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 13, 2021, 2:51am UTC](https://discuss.elastic.co/t/how-to-write-while-loops-inside-logstash-elasticsearch/278805/4 "2021-08-13T02:51:51Z")

</div>

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