# Aggregate

**URL:** <https://discuss.elastic.co/t/aggregate/189505>\
**Category:** Logstash\
**Created:** [July 9, 2019, 9:43am UTC](https://discuss.elastic.co/t/aggregate/189505 "2019-07-09T09:43:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreasky](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@Andreasky](https://discuss.elastic.co/u/Andreasky)\
**Post date:** [July 9, 2019, 9:43am UTC](https://discuss.elastic.co/t/aggregate/189505/1 "2019-07-09T09:43:46Z")

</div>

```
aggregate{
    		task_id => "%{Response}"
         	code =>"
                    if(event.get(Response) == "answered")
         		       map['answers'] ||= 0;
    			       map['answers'] += 1;
                    end
        	"
        	push_map_as_event_on_timeout => true
        	timeout_task_id_field => "callMessage"
        	timeout => 60
        	timeout_tags => ['_aggregatetimeout']
			timeout_code => "event.set('several_incomings', event.get('answers') > 1)"

    	}

```

When I use this in my logstash configuration file, I get this error message:

```
[ERROR][logstash.agent] Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Expected one of #, {, } 

```

I don't understand what's wrong. When I remove the if statement, it works, but I only want to count the "answered" calls.

---

<div class="post-metadata">

**Author:** ![Jenni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jenni/32/29684_2.png) [@Jenni](https://discuss.elastic.co/u/Jenni)\
**Post date:** [July 9, 2019, 10:29am UTC](https://discuss.elastic.co/t/aggregate/189505/2 "2019-07-09T10:29:31Z")

</div>

There's a double quoted string in your condition and your code is wrapped in double quotes as well. That's why the parser thinks your code ends after == " and everything else is nonsense. Try

`== 'answered')`

instead

---

<div class="post-metadata">

**Author:** ![Andreasky](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@Andreasky](https://discuss.elastic.co/u/Andreasky)\
**Post date:** [July 9, 2019, 10:51am UTC](https://discuss.elastic.co/t/aggregate/189505/3 "2019-07-09T10:51:41Z")

</div>

Thank you!

---

<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:** [August 6, 2019, 10:51am UTC](https://discuss.elastic.co/t/aggregate/189505/4 "2019-08-06T10:51:45Z")

</div>

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