title: How to set an Elasticsearch output template in Logstash
body: <p>I’m relatively new to Kibana and the ELK (Elasticsearch, Logstash and Kibana) stack and I’ve been doing pretty well setting one up, but I have run into what I see as an odd issue and need some help understanding what’s happening.</p>
  
  <p>I’m using the ELK stack to crunch some Apache logs but I have my own custom type settings. So I need to explicitly specify field types and such instead of having Logstash (or is it Kibana?) guess what the data mapping would be.</p>
  
  <p>From <a href="https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-template" rel="noreferrer">reading the Logstash documentation</a>, it seems pretty clear that I can set the <code>template</code> value in the <code>output.elasticsearch</code> chunk of config shown here:</p>
  
  <pre><code>output {
    elasticsearch {
      hosts =&gt; ["localhost:9200"]
      index =&gt; "logstash-apache"
      document_id =&gt; "%{[@metadata][fingerprint]}"
      manage_template =&gt; false
      template =&gt; "/path/to/logstash/logstash-apache.json"
      template_name =&gt; "logstash-apache"
      template_overwrite =&gt; true
    }
    stdout {
      codec =&gt; rubydebug
    }
  }
  </code></pre>
  
  <p>100% sure I have the correct path set. But for some reason, if I use this, launch Logstash and let it do it’s things, the mappings I have specified in <code>logstash-apache.json</code> don’t show up. The index in Kibana is <code>logstash-apache</code> as well so this should work right?</p>
  
  <p>So what I do now is preload the mappings template directly into Elasticsearch like this:</p>
  
  <pre><code>curl -ss -XPUT "http://localhost:9200/_template/logstash-apache/" -H 'Content-Type: application/json' -d @"/path/to/logstash/logstash-apache.json";
  </code></pre>
  
  <p>And it clearly works well and the data gets proper mapping… But doing something like this is fairly clunky. It would be cleaner to just have it all come from the <code>logstash-apache.conf</code> file I have setup.</p>
  
  <p>So what am I doing wrong? What can I do to have my custom mappings template be used via that <code>logstash-apache.conf</code> without having to jump through the extra hoop of a <code>curl</code> command?</p>