_default_ mappingedit

The default mapping, which will be used as the base mapping for any new mapping types, can be customised by adding a mapping type with the name _default_ to an index, either when creating the index or later on with the PUT mapping API.

PUT my_index
{
  "mappings": {
    "_default_": { 
      "_all": {
        "enabled": false
      }
    },
    "user": {}, 
    "blogpost": { 
      "_all": {
        "enabled": true
      }
    }
  }
}

The _default_ mapping defaults the _all field to disabled.

The user type inherits the settings from _default_.

The blogpost type overrides the defaults and enables the _all field.

While the _default_ mapping can be updated after an index has been created, the new defaults will only affect mapping types that are created afterwards.

The _default_ mapping can be used in conjunction with Index templates to control dynamically created types within automatically created indices:

PUT _template/logging
{
  "template":   "logs-*", 
  "settings": { "number_of_shards": 1 }, 
  "mappings": {
    "_default_": {
      "_all": { 
        "enabled": false
      },
      "dynamic_templates": [
        {
          "strings": { 
            "match_mapping_type": "string",
            "mapping": {
              "type": "string",
              "fields": {
                "raw": {
                  "type":  "string",
                  "index": "not_analyzed",
                  "ignore_above": 256
                }
              }
            }
          }
        }
      ]
    }
  }
}

PUT logs-2015.10.01/event/1
{ "message": "error:16" }

The logging template will match any indices beginning with logs-.

Matching indices will be created with a single primary shard.

The _all field will be disabled by default for new type mappings.

String fields will be created with an analyzed main field, and a not_analyzed .raw field.