Your rex statement is wrong and even when fixed, it extracts duration as the string duration 300 i.e. the full text, so you should use this rex | rex field=_raw "(?<time>.*),(?<alert_num>.*),(?<error>.*),\s?duration\s+(?<duration>\d+)"
| eventstats max(duration) as maxDuration by alert_num
| where duration=maxDuration so your duration field is extracted as a number rather than a string. Then simply add the by alert_num onto your eventstats. Note that you should still make your regex more robust. Using a greedy .* wildcard selection can easily cause your regex to break. For example as you know your field delimiter is a comma, use | rex field=_raw "(?<time>[^,]*),(?<alert_num>[^,]),(?<error>[^,]),\s?duration\s+(?<duration>\d+)"
... View more