title: Compression to Elasticsearch indexes
body: <p>Is there a way to set default compression method to best_compression with newly created indexes in Elasticsearch?</p>
  
  <p>Obviously it can be done manually after index has been created.</p>
  
  <p>Based on googling, this should be achievable either by setting it in elasticsearch.yml, or by creating a custom template to set it. However, I haven't been able to get it right in elasticsearch.yml. I've tried all sorts of variations, but basically this should do it:</p>
  
  <pre><code>index.codec: best_compression
  </code></pre>
  
  <p>But it doesn't.</p>
  
  <p>I'm also not comfortable with creating a custom template, since my goal is to get this compression to all indexes, not just those created using some specific template. But if it's the only way, so be it.</p>
  
  <p>My use case is Elasticsearch with Logstash, so Logstash is the creator of these indexes. Without custom templates, setting the compression method in Logstash configs seems completely impossible.  I'm running Elasticsearch version 2.2.0.</p>
  
  <p>Currently I can set the compression manually just fine after closing index and executing:</p>
  
  <pre><code>curl -XPUT 'http://localhost:9200/example_index/_settings' -d '{"index":{"codec":"best_compression"}}'
  </code></pre>
  
  <p>And then reopening the index.</p>
  
  <p>From official documentation:</p>
  
  <pre><code>index.codec
  </code></pre>
  
  <blockquote>
    <p>The default value compresses stored data with LZ4 compression, but
    this can be set to best_compression which uses DEFLATE for a higher
    compression ratio, at the expense of slower stored fields performance.</p>
  </blockquote>
  
  <p>Source: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html" rel="noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html</a></p>