# Clone multiple JSON events from input source count

**URL:** https://discuss.elastic.co/t/clone-multiple-json-events-from-input-source-count/153512
**Category:** Logstash
**Created:** [October 23, 2018, 3:55am UTC](https://discuss.elastic.co/t/clone-multiple-json-events-from-input-source-count/153512 "2018-10-23T03:55:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rocket](https://avatars.discourse-cdn.com/v4/letter/r/e79b87/32.png) [@rocket](https://discuss.elastic.co/u/rocket)
#### Post date: [October 23, 2018, 3:55am UTC](https://discuss.elastic.co/t/clone-multiple-json-events-from-input-source-count/153512/1 "2018-10-23T03:55:29Z")

</div>

Receiving JSON input lines with count value as one of the fields. Count value should be used to clone elasticsearch events before ingesting in elasticsearch. Tried ruby code below to loop the count and could not get the clone to work. Please advise sample Ruby code to process this request and ingest in Elasticsearch.

Logstash version : 5.6.8

Input line : { "key1" : value 1, "key2" : value2, "key 3" : new\_req}

Logstash filter code.

```
filter{
            ruby { code => "event.set('clone_count', Integer(event.get('new_req') - 1")) }
            mutate { add_tag => ["cloneme"] }
            if "cloneme" in [tags] {
               if "cloned" not in [tags] {
                 mutate { add_tag => ["cloned"] }
                 ruby {
                        code => "
                           for i in 0..Integer(event.get('clone_count'))
                              clone {
                                  clones => ["cloned"]
                              }
                           end
                         "
                      }
              }
        }
}
```

---

<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 20, 2018, 3:55am UTC](https://discuss.elastic.co/t/clone-multiple-json-events-from-input-source-count/153512/2 "2018-11-20T03:55:29Z")

</div>

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