# Having problem with Logstash filter aggregate example

**URL:** <https://discuss.elastic.co/t/having-problem-with-logstash-filter-aggregate-example/57092>\
**Category:** Logstash\
**Created:** [August 3, 2016, 10:46am UTC](https://discuss.elastic.co/t/having-problem-with-logstash-filter-aggregate-example/57092 "2016-08-03T10:46:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishwanathh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vishwanathh/32/51337_2.png) [@vishwanathh](https://discuss.elastic.co/u/vishwanathh)\
**Post date:** [August 3, 2016, 10:46am UTC](https://discuss.elastic.co/t/having-problem-with-logstash-filter-aggregate-example/57092/1 "2016-08-03T10:46:12Z")

</div>

Hello,

I'm not getting the desired output for this example that I"m testing on my windows machine.

**file: sqllog**  
INFO - 12345 - TASK\_START - start  
INFO - 12345 - SQL - sqlQuery1 - 12  
INFO - 12345 - SQL - sqlQuery2 - 34  
INFO - 12345 - TASK\_END - end

**file: logstash-sql.conf**  
input {  
file {  
path =\> "C:\logstash\sqllog"  
start\_position =\> beginning  
}  
}

```
filter {
   grok {
     match => ["message", "%{LOGLEVEL:loglevel} - %{NOTSPACE:taskid} - %{NOTSPACE:logger} - %{WORD:label}( - %{INT:duration:int})?"]
   }

   if [logger] == "TASK_START" {
     aggregate {
       task_id => "%{taskid}"
       code => "map['sql_duration'] = 0"
       map_action => "create"
     }
   }

   if [logger] == "SQL" {
     aggregate {
       task_id => "%{taskid}"
       code => "map['sql_duration'] += event['duration']"
       map_action => "update"
     }
   }

   if [logger] == "TASK_END" {
     aggregate {
       task_id => "%{taskid}"
       code => "event['sql_duration'] = map['sql_duration']"
       map_action => "update"
       end_of_task => true
       timeout => 120
     }
   }
 }

 output {
  stdout {}
 }

```

**Running Logstash:**  
_\>logstash.bat -f C:\logstash\logstash-sql.conf -w 1_

Settings: User set pipeline workers: 1, Default pipeline workers: 4  
Pipeline main started  
2016-08-03T09:56:50.382Z PGGV999 INFO - 12345 - TASK\_START - start  
2016-08-03T09:56:50.569Z PGGV999 INFO - 12345 - SQL - sqlQuery1 - 12  
2016-08-03T09:56:50.570Z PGGV999 INFO - 12345 - SQL - sqlQuery2 - 34

The pipeline ends here, but I'm expecting:  
{  
"message" =\> "INFO - 12345 - TASK\_END - end",  
"sql\_duration" =\> 46  
}

Can someone help what I'm doing wrong here?

Thanks.

---

<div class="post-metadata">

**Author:** ![vishwanathh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vishwanathh/32/51337_2.png) [@vishwanathh](https://discuss.elastic.co/u/vishwanathh)\
**Post date:** [August 3, 2016, 1:51pm UTC](https://discuss.elastic.co/t/having-problem-with-logstash-filter-aggregate-example/57092/2 "2016-08-03T13:51:20Z")

</div>

I could solve it myself. The sqllog did not have a "\n" for the last line and it was troubling the logstash execution. Introducing a "\n" for last line helped to get the right output.

Also used rubydebug codec to understand how it is printing.

---

<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, 4:45am UTC](https://discuss.elastic.co/t/having-problem-with-logstash-filter-aggregate-example/57092/3 "2017-07-06T04:45:06Z")

</div>


