_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
{
  "settings": {
    "mapping.single_type": false
  },
  "mappings": {
    "_default_": { 
      "_source": {
        "enabled": false
      }
    },
    "user": {}, 
    "blogpost": { 
      "_source": {
        "enabled": true
      }
    }
  }
}

The _default_ mapping defaults the _source field to disabled.

The user type inherits the settings from _default_.

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

Note

When updating the _default_ mapping with the PUT mapping API, the new mapping is not merged with the existing mapping. Instead, the new _default_ mapping replaces the existing one.

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
{
  "index_patterns":   ["logs-*"], 
  "settings": { "number_of_shards": 1 }, 
  "mappings": {
    "_default_": {
      "_field_names": { 
        "enabled": false
      },
      "dynamic_templates": [
        {
          "strings": { 
            "match_mapping_type": "string",
            "mapping": {
              "type": "text",
              "fields": {
                "raw": {
                  "type":  "keyword",
                  "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 _field_names field will be disabled by default for new type mappings.

String fields will be created with a text main field, and a keyword .raw field.