# Multiple consecutive lines with no unique identifier

**URL:** <https://discuss.elastic.co/t/multiple-consecutive-lines-with-no-unique-identifier/177600>\
**Category:** Logstash\
**Created:** [April 19, 2019, 10:15am UTC](https://discuss.elastic.co/t/multiple-consecutive-lines-with-no-unique-identifier/177600 "2019-04-19T10:15:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![agiorgi](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@agiorgi](https://discuss.elastic.co/u/agiorgi)\
**Post date:** [April 19, 2019, 10:15am UTC](https://discuss.elastic.co/t/multiple-consecutive-lines-with-no-unique-identifier/177600/1 "2019-04-19T10:15:57Z")

</div>

**Hello everyone!**  
This is my first post here on elastic fourm 😄 so please excuse me if i'm breaking any rules...

I'm trying to parse a log file from a message broker. The logs are very heterogeneus, and have no unique ID for a ""transaction"".  
Or better, they do have one. But it isn't uniq. It connects different types of logs. But i want separate documents for each type of log.

##### A sample of the logs is as follows:####

```
22/10 08:42:25 DEBUG hostname.full.com - ID: 2894712 Request: reqbody here
22/10 08:42:25 DEBUG hostname.full.com - ID: 2894712 Response da BSP: response body
22/10 08:42:25 DEBUG hostname.full.com - ID: 2894712 dummy data here
22/10 08:42:25 DEBUG hostname.full.com - ID: 2894712 warnings here
22/10 08:42:25 DEBUG hostname.full.com - ID: 2894712 fetch some data: body
22/10 08:42:25 DEBUG hostname.full.com - ID: 2894712 fetch some data response: body
22/10 08:42:25 DEBUG hostname.full.com - ID: 2894712 end evaluating msgs

```

###### ANOTHER KIND OF LOG FOLLOWING HERE:

```
22/10 08:41:33 DEBUG hostname.full.com - ID: 2894712 MQSender start write message: message body
22/10 08:41:33 DEBUG hostname.full.com - ID: 2894712 queueConnFactoryName: broker
22/10 08:41:33 DEBUG hostname.full.com - ID: 2894712 queueName: name
22/10 08:41:33 DEBUG hostname.full.com - ID: 2894712 txtMsg
	SourceMF
	muliline 
	jms_text
	handleRequest ...
22/10 08:41:33 DEBUG hostname.full.com - ID: 2894712 message sent!
22/10 08:41:33 DEBUG hostname.full.com - ID: 2894712 MQSender end!

```

There are even more kind of logs, but i'd rather keep it as simple as i can.  
What i'd like to obtain is 2 documents, like these ones:

```
{ "timestamp": "22/10 08:41:33",
   "facility": "DEBUG",
   "hostname": "hostname.full.com",
   "id": "2894712",
   "request_body": "reqbody here",
   "response_body": "response body",
   "fetch_data_request": "body",
   "fetch_data_response": "body"
}

```

###### AND

```
{ "timestamp": "22/10 08:41:33",
   "facility": "DEBUG",
   "hostname": "hostname.full.com",
   "id": "2894712",
   "message_body": "message body",
   "queue_conn_factory_name": "broker",
   "queue_conn_name": "name",
   "text_msg": "text body"
}

```

As of now i can easily aggregate multiline logs (like the txtMsg up here) with the multline filter.  
My problem is aggregating the different types of logs with the aggregate filter, but i can't get it to work.

If it's unclear or you'd need more details please just let me know 😀  
Thanks a lot!  
Alessandro

---

<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:** [April 19, 2019, 3:44pm UTC](https://discuss.elastic.co/t/multiple-consecutive-lines-with-no-unique-identifier/177600/2 "2019-04-19T15:44:24Z")

</div>

Here is an example of how to handle the first type of log

```
    dissect { mapping => { "message" => "%{ts} %{+ts} %{level} %{hostname} - ID: %{id} %{restOfLine}" } }
    grok {
        match => {
            "restOfLine" => [
                "Request: %{GREEDYDATA:requestBody}",
                "Response da BSP: %{GREEDYDATA:responseBody}",
                "fetch some data: %{GREEDYDATA:fetchDataRequest}",
                "fetch some data response: %{GREEDYDATA:fetchDataResponse}"
            ]
        }
    }
    aggregate {
        task_id => "%{id}"
        code => '
            map["timestamp"] = event.get("ts")
            map["hostname"] = event.get("hostname")
            if event.get("requestBody") then map["requestBody"] = event.get("requestBody") ; end
            if event.get("responseBody") then map["responseBody"] = event.get("responseBody") ; end
            if event.get("fetchDataRequest") then map["fetchDataRequest"] = event.get("fetchDataRequest") ; end
            if event.get("fetchDataResponse") then map["fetchDataResponse"] = event.get("fetchDataResponse") ; end
            event.cancel
        '
        push_map_as_event_on_timeout => true
        timeout_task_id_field => "id"
        timeout => 6
    }
```

---

<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:** [May 17, 2019, 3:52pm UTC](https://discuss.elastic.co/t/multiple-consecutive-lines-with-no-unique-identifier/177600/3 "2019-05-17T15:52:03Z")

</div>

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