title: Fluentd create a tag based on a field value
body: <p>I have a <code>Kubernetes</code> cluster in which i'm trying to aggregate container logs on the nodes and send them to <code>MongoDB</code>. However i need to be able to send the log records to different MongoDB servers based on values in the log record it self.</p>
  
  <p>I'm using the <a href="https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter" rel="nofollow noreferrer">fluent-plugin-kubernetes_metadata_filter</a> plugin to attach additional information from Kubernetes to the log record. One of those fields are <code>kubernetes_namespace_name</code>. Is it possible to use that field to create a tag which i can use to match against the mongodb output plugin.   </p>
  
  <p>For example. Below i'm using only one output, but the idea is to have multiple and let fluent send the logs to that mongodb database based on the value in the field <code>kubernetes_namespace_name</code>:</p>
  
  <pre><code>&lt;source&gt;
    @type tail
    @label @KUBERNETES
    path /var/log/containers/*.log
    pos_file /var/log/es-containers.log.pos
    time_format %Y-%m-%dT%H:%M:%S
    tag kubernetes.*
    format json
    keep_time_key true
    read_from_head true
  &lt;/source&gt;
  
  &lt;label @KUBERNETES&gt;
    &lt;filter kubernetes.**&gt;
      @type kubernetes_metadata
      kubernetes_url "#{ENV['K8S_HOST_URL']}"
      bearer_token_file /var/run/secrets/kubernetes.io/serviceaccount/token
      ca_file /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
      include_namespace_id true
    &lt;/filter&gt;
    &lt;filter kubernetes.**&gt;
      @type flatten_hash
      separator _
    &lt;/filter&gt;
  
    # &lt; Tag 'kubernetes.namespace.default' is created here somehow &gt;
  
    &lt;match kubernetes.namespace.default&gt;
      @type mongo
      host "#{ENV['MONGO_HOST']}"
      port "#{ENV['MONGO_PORT']}"
      database "#{ENV['MONGO_DATABASE']}"
      collection "#{ENV['MONGO_COLLECTION']}"
      capped
      capped_size 1024m
      user "#{ENV['MONGO_USER']}"
      password "#{ENV['MONGO_PASSWORD']}"
      time_key time
      flush_interval 10s
    &lt;/match&gt;
  &lt;/label&gt;
  </code></pre>