# Logstash multiline and clone

**URL:** <https://discuss.elastic.co/t/logstash-multiline-and-clone/320478>\
**Category:** Logstash\
**Created:** [December 5, 2022, 3:18pm UTC](https://discuss.elastic.co/t/logstash-multiline-and-clone/320478 "2022-12-05T15:18:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrianfusco](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adrianfusco/32/111798_2.png) [@adrianfusco](https://discuss.elastic.co/u/adrianfusco)\
**Post date:** [December 5, 2022, 3:18pm UTC](https://discuss.elastic.co/t/logstash-multiline-and-clone/320478/1 "2022-12-05T15:18:17Z")

</div>

I am sending some information from filebeat using one kind of multiline pattern.

At some point, I realized I need to use another multiline pattern based on the log\_source.

My idea was `clone` the beat and if the `log_source` match the one I need and the type is `clone`, apply another multiline pattern on this one to send the information into different documents and not a single one into another index.

The thing is that I think I should apply it in the `filtering` side for being able to do it, but this plugin has been deprecated: [Multiline filter plugin | Logstash Reference [8.5] | Elastic](https://www.elastic.co/guide/en/logstash/current/plugins-filters-multiline.html)

Something like this:

```auto
input {
    beats {
        port => 5044
    }
}

filter {
    if [log_source] == "logs_for_filter" {
        clone {
            clones => ["cloned_logs_for_filter"]
        }
    }
    
    if [type] == "cloned_logs_for_filter" {
        multiline {
            pattern => "(^<case)"
            negate => true
            what => previous
        }
    }
    if [log_source] == "logs_for_filter" and "cloned_logs_for_filter" not in [type] {
       # do things
    }
}
output {
    stdout {
        codec => rubydebug
    }
    if [type] == "cloned_logs_for_filter" {
        elasticsearch {
            hosts => "elasticsearch:9200"
            index => "index_2"
        }
    }
    else {
        elasticsearch {
            hosts => "elasticsearch:9200"
            index => "index_two"
        }
    }
}

```

Do you think there's another way to do it? Thank you.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [December 5, 2022, 4:26pm UTC](https://discuss.elastic.co/t/logstash-multiline-and-clone/320478/2 "2022-12-05T16:26:10Z")

</div>

It won't work this way.

You need to configure multiline in the source, in this case, you need to configure it in beats.

The best option would be to use a different log input for each kind of multiline you have.

---

<div class="post-metadata">

**Author:** ![adrianfusco](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adrianfusco/32/111798_2.png) [@adrianfusco](https://discuss.elastic.co/u/adrianfusco)\
**Post date:** [December 5, 2022, 4:28pm UTC](https://discuss.elastic.co/t/logstash-multiline-and-clone/320478/3 "2022-12-05T16:28:40Z")

</div>

That's another good solution @leandrojmp thank you very much.

--

At the end I've applied the `split` plugin

```auto
        split {
            field => "message"
            terminator => "
"
        }

```

And then pass the grok filter in each one of them. At this way it's storing each match in different documents.

---

<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:** [January 2, 2023, 4:29pm UTC](https://discuss.elastic.co/t/logstash-multiline-and-clone/320478/4 "2023-01-02T16:29:06Z")

</div>

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