title: Elasticsearch default mapping
body: <p><strong>My current understanding-</strong></p>
  
  <ol>
  <li>Elasticsearch creates the mapping indices the first time it receives the JSON datasets.</li>
  <li>This mapping cannot be changed, but the datasets can be re-mapped.</li>
  </ol>
  
  <p><strong>Question-</strong></p>
  
  <p>Forget re-mapping. Is there any way to tell ES to behave <em>by default</em> as-</p>
  
  <p><code>"Consider everything that is not a date to be of string type"</code>?</p>
  
  <p>Also, will i be losing out on much if i do this?</p>
  
  <p><strong>Update-</strong></p>
  
  <p>i added the file- <code>config/mappings/_default/mapping.json</code> with the following contents-</p>
  
  <pre><code>{
      "dynamic_templates": [
          {
              "template_1": {
                  "match": "*",
                  "match_mapping_type": "int",
                  "mapping": {
                      "type": "string"
                  }
              },
              "template_2": {
                  "match": "*",
                  "match_mapping_type": "long",
                  "mapping": {
                      "type": "string"
                  }
              }
          }
      ]
  }
  </code></pre>
  
  <p>i also tried placing the following at- <code>config/default_mapping.json</code></p>
  
  <pre><code>{
      "_default_" : {
          "match": "*",
          "match_mapping_type": "int",
          "mapping": {
                  "type": "string"
          }
      }
  }
  </code></pre>
  
  <p>My 'motive' is to get rid of errors that crop up if <code>int</code> and <code>long</code> types change to <code>string</code>. Will this map <em>all</em> <code>int</code> and <code>long</code> values as <code>string</code> across all indexes that are created in the future? Do i need to nest this <code>dynamic_templates</code> key within <code>_all</code>?</p>
  
  <p><strong>Update II-</strong></p>
  
  <p>Adding this mapping file causes elasticsearch to cough up-</p>
  
  <pre><code>[2014-02-04 10:48:34,396][DEBUG][action.admin.indices.create] [Her] [logstash-2014.02.04] failed to create
  org.elasticsearch.index.mapper.MapperParsingException: mapping [mapping.json]
      at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$2.execute(MetaDataCreateIndexService.java:312)
      at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:298)
      at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:135)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:701)
  Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map
      at org.elasticsearch.index.mapper.DocumentMapperParser.extractMapping(DocumentMapperParser.java:268)
      at org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:155)
      at org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:314)
      at org.elasticsearch.index.mapper.MapperService.merge(MapperService.java:193)
      at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$2.execute(MetaDataCreateIndexService.java:309)
      ... 5 more
  2014-02-04 10:48:34 +0000 [warn]: temporarily failed to flush the buffer. next_retry=2014-02-04 10:48:33 +0000 error_class="Net::HTTPServerException" error="400 \"Bad Request\"" instance=17509700
  </code></pre>