How to count log entries based on a filter

I just answered a very similar question here: Finding most frequently accessed URI-paths / Transactions using Logstash