# Aggregates all lines messages between 2 date using multiline filter

**URL:** <https://discuss.elastic.co/t/aggregates-all-lines-messages-between-2-date-using-multiline-filter/27823>\
**Category:** Logstash\
**Created:** [August 21, 2015, 8:46am UTC](https://discuss.elastic.co/t/aggregates-all-lines-messages-between-2-date-using-multiline-filter/27823 "2015-08-21T08:46:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelScofield](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michaelscofield/32/4118_2.png) [@MichaelScofield](https://discuss.elastic.co/u/MichaelScofield)\
**Post date:** [August 21, 2015, 8:46am UTC](https://discuss.elastic.co/t/aggregates-all-lines-messages-between-2-date-using-multiline-filter/27823/1 "2015-08-21T08:46:07Z")

</div>

I have a log like this:

```
2015-06-26 23:00:48,935 foo as "date1"
whatever lines not start with date
...
2015-06-16 18:46:16,136 bar as "date2"

```

I'm trying to get all lines between date1(include) and date2(exclude). So I use "multiline" filter:

```
filter {
    grok {
        match => {"message" => "%{TIMESTAMP_ISO8601:[@metadata][tt]} %{GREEDYDATA:[@metadata][dd]}"}
    }
    if "_grokparsefailure" not in [tags] {
         date {
             match => ["[@metadata][tt]", "yyyy-MM-dd HH:mm:ss,SSS"]
         }
     } else { # indicates this line should belong to previous message
         multiline {
             pattern => ".*"
             what => "previous"
         }
     }
 }

```

But it just generates 3 messages:

```
m1: 2015-06-26 23:00:48,935 foo
m2: 2015-06-16 18:46:16,136 bar
m3: whatever lines not start with date
    ...

```

What's wrong with the filter config? How to make it right? Thx in advance!

---

<div class="post-metadata">

**Author:** ![MichaelScofield](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michaelscofield/32/4118_2.png) [@MichaelScofield](https://discuss.elastic.co/u/MichaelScofield)\
**Post date:** [August 21, 2015, 9:38am UTC](https://discuss.elastic.co/t/aggregates-all-lines-messages-between-2-date-using-multiline-filter/27823/2 "2015-08-21T09:38:35Z")

</div>

Answering my own question after I solved it:

```
filter {
    multiline {
        pattern => "^%{TIMESTAMP_ISO8601}"
        negate => true
        what => "previous"
    }
    grok {
        match => {"message" => "%{TIMESTAMP_ISO8601:[@metadata][tt]} %{GREEDYDATA:[@metadata][dd]}"}
    }
    date {
        match => ["[@metadata][tt]", "yyyy-MM-dd HH:mm:ss,SSS"]
    }
}
```

---

<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 6, 2017, 5:31am UTC](https://discuss.elastic.co/t/aggregates-all-lines-messages-between-2-date-using-multiline-filter/27823/3 "2017-07-06T05:31:22Z")

</div>

Closed on July 6, 2017, 5:31am UTC


