# Logstash aggregate function

**URL:** <https://discuss.elastic.co/t/logstash-aggregate-function/258738>\
**Category:** Logstash\
**Created:** [December 15, 2020, 4:09pm UTC](https://discuss.elastic.co/t/logstash-aggregate-function/258738 "2020-12-15T16:09:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![errupeshmca](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/errupeshmca/32/78285_2.png) [@errupeshmca](https://discuss.elastic.co/u/errupeshmca)\
**Post date:** [December 15, 2020, 4:09pm UTC](https://discuss.elastic.co/t/logstash-aggregate-function/258738/1 "2020-12-15T16:09:54Z")

</div>

I am looking for aggregate function to get sum of field(TotalOrderReceivedToday) in a new field (sum). but i think it's aggregating everything based on TotalOrderReceivedToday field, I need sum of one field only to

```auto
{
           "Salesperson name" => "Online Order",
            "Order Complete?" => "True",
         "Expected Ship Date" => 2020-08-05T04:00:00.000Z,
                 "Order Type" => "O",
          "Total Order Value" => 301.0,
                       "host" => "server",
                 "@timestamp" => 2020-12-14T19:04:07.973Z,
                       "path" => "D:/ELK/logstash-7.9.3/config/TotatOrderOfDay.csv",
                      "Inv #" => " 461872",
                 "Order Date" => 2020-08-05T04:00:00.000Z,
                      "Doc #" => 461872,
    "TotalOrderReceivedToday" => 1,
                    "message" => "\"I 461872\",\" 1170\",\"I\",\" 461872\",\" 416889\",\"O\",\"True\",05-Aug-20,301,340.13,0,\" 461872\",07-Aug-20,05-Aug-20,07-Aug-20,0,0,\" WEB\",\"Online Order\",\" GS\",0\r",
                   "Doc Type" => "I",
                    "Order #" => 416889,
             "ThisWeekOrders" => 0,
                   "Inv Date" => 2020-08-07T04:00:00.000Z,
                "Salesperson" => " WEB",
                     "Cust #" => 1170,
                   "@version" => "1",
         "Total Dollar Value" => 340.13,
               "TotalShipped" => 0,
                  "Order Key" => "I 461872",
                        "Loc" => " GS",
              "Shipment Date" => 2020-08-07T04:00:00.000Z,
               "Order Status" => "AlreadyInvoiced",
           "ShippedYesterday" => 0
}

```

Aggregation function   
aggregate {  
task\_id =\> "%{TotalOrderReceivedToday}"  
code =\> "map['action'] ||= ''  
map['action'] = event.get('TotalOrderReceivedToday')  
map['sum'] ||= 0  
map['sum'] += 1  
event.cancel"  
push\_map\_as\_event\_on\_timeout =\> true  
timeout\_task\_id\_field =\> "TotalOrderReceivedToday"  
timeout =\> 10  
}

---

<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 12, 2021, 4:10pm UTC](https://discuss.elastic.co/t/logstash-aggregate-function/258738/2 "2021-01-12T16:10:01Z")

</div>

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