title: Fluentd - Using source tag as index
body: <p>I have a setup with Fluentd and Elasticsearch running on a Docker engine.  I have swarms of services which I would like to log to Fluentd.</p>
  
  <p>What I want to do is create a tag for each service that I run and use that tag as an index in Elasticsearch.  Here's the setup that I have:</p>
  
  <pre><code>&lt;source&gt;
    @type forward
    port 24224
    bind 0.0.0.0
  &lt;/source&gt;
  
  &lt;match docker.service1&gt;
    @type elasticsearch
    host "172.20.0.3"
    port 9200
    index_name service1
    type_name fluentd
    flush_interval 10s
  &lt;/match&gt;
  
  &lt;match docker.service2&gt;
    @type elasticsearch
    host "172.20.0.3"
    port 9200
    index_name service2
    type_name fluentd
    flush_interval 10s
  &lt;/match&gt;
  </code></pre>
  
  <p>and so forth.</p>
  
  <p>It would be annoying to have to include a new match tag for every single service I create, because I want to be able to add new service without updating my fluentd configuration.  Is there a way to do something like this:</p>
  
  <pre><code>&lt;source&gt;
    @type forward
    port 24224
    bind 0.0.0.0
  &lt;/source&gt;
  
  &lt;match docker.**&gt;
    @type elasticsearch
    host "172.20.0.3"
    port 9200
    index_name $(TAG)
    type_name fluentd
    flush_interval 10s
  &lt;/match&gt;
  </code></pre>
  
  <p>Where I use a $(TAG) variable to indicate that I want the Tag name to be the name of the index?</p>
  
  <p>I've tried this from an answer I found <a href="https://stackoverflow.com/questions/27233761/can-you-use-environment-variables-in-config-file-for-fluentd">here</a>: ${tag_parts[0]}.  This was printed literally as my index.  So my index was "${tag_parts[0]}".</p>
  
  <p>Thanks in advance.</p>