title: Adding tags to logstash events based on the md5 of the filename
body: <p>I'm trying to link logstash events with the eventual file location on AWS S3. We have the logstash agent indexing files directly, and when the file has finished being written to, we send it to S3.</p>
  
  <p>To increase S3 performance, we're fanning out files by storing them like so:</p>
  
  <pre><code>hex(md5(filename.log))[0..2]/filename.log
  </code></pre>
  
  <p>This takes the first 3 characters of the md5 hexdigest, and stores the file in the folder with that prefix, providing a fairly solid fan out of files. Unfortunately, I can't work out how to tag each log event with this information.</p>
  
  <p>There is the <a href="http://logstash.net/docs/1.2.2/filters/ruby" rel="nofollow">ruby filter type</a> which allows you to execute ruby code, but I don't think it allows you to use the result of the computation.</p>
  
  <pre><code>filter {
    ruby {
      code =&gt; "require 'digest/md5'; Digest::MD5.hexdigest("mylong.file.name")[0..2]"
      # now what?
    }
  }
  </code></pre>
  
  <p>Is there a way of attaching a tag or field based on a prefix of the md5?</p>