Removal of Mapping Types in Elasticsearch 6.0

Mapping types are going away. Elasticsearch 6.0 supports a single mapping
type per index only, and it represents the first step on the way to removing
types altogether.

This blog post explains what types are, why we are removing them, how you can
migrate your indices to a single type world, and lays out the full schedule
for type removal over the next three major versions.

  • What are mapping types?
  • Why are mapping types being removed?
  • Alternatives to mapping types
    • Custom type field
    • Index per document type
  • Parent/Child without mapping types
  • Schedule for removal of mapping types
  • Migrating multi-type indices to single-type
    • Custom type field
    • Index per document type

<tldr>

  • Indices created in Elasticsearch 6.0.0 or later may contain a
    single mapping type only.
  • Indices created in 5.x with multiple
    mapping types will continue to function as before in Elasticsearch 6.x.
  • Mapping types will be completely removed in Elasticsearch 7.0.0
    although some backwards compatibility features will only be removed in 9.0.0.

</tldr>

parent-child relationship between documents, so documents of type question could be parents to
documents of type answer.

join field.

join field replacement for parent-child is available on indices created in 5.6.

Elasticsearch 6.x

  • Indices created in 5.x will continue to function in 6.x as they did in 5.x.
  • Indices created in 6.x only allow a single-type per index. Any name can be used for the type, but there can be only one.
  • The _type name can no longer be combined with the _id to form the _uid field. The _uid field has become an alias for the _id field.
  • New indices no longer support the old-style of parent/child and should use the join field instead.
  • The _default_ mapping type is deprecated.

Elasticsearch 7.x

  • The type parameter in URLs are optional. For instance, indexing a document no longer requires a document type.
  • The GET|PUT _mapping APIs support a query string parameter ( include_type_name) which indicates whether the body should include a layer for the type name. It defaults to true. 7.x indices which don’t have an explicit type will use the dummy type name _doc.
  • The _default_ mapping type is removed.

Elasticsearch 8.x

  • The type parameter is no longer supported in URLs.
  • The include_type_name parameter defaults to false.

Elasticsearch 9.x

  • The include_in_type parameter is removed.

Reindex API can be used to convert multi-type indices to
single-type indices. The following examples can be used in Elasticsearch 5.6
or Elasticsearch 6.x. In 6.x, there is no need to specify index.mapping.single_type as that is the default.

Custom type field

This first example adds a custom type field and sets it to the value of the
original _type. It also adds the type to the _id in case there are any
documents of different types which have conflicting IDs:

PUT new_twitter
{ "mappings": { "doc": { "properties": { "type": { "type": "keyword" }, "name": { "type": "text" }, "user_name": { "type": "keyword" }, "email": { "type": "keyword" }, "content": { "type": "text" }, "tweeted_at": { "type": "date" } } } }
}
POST _reindex
{ "source": { "index": "twitter" }, "dest": { "index": "new_twitter" }, "script": { "source": """ ctx._source.type = ctx._type; ctx._id = ctx._type + '-' + ctx._id; ctx._type = 'doc'; """ }
} 

Index per document type

This next example splits our twitter index into a tweets index and a users index:

PUT users
{ "settings": { "index.mapping.single_type": true }, "mappings": { "user": { "properties": { "name": { "type": "text" }, "user_name": { "type": "keyword" }, "email": { "type": "keyword" } } } }
}
PUT tweets
{ "settings": { "index.mapping.single_type": true }, "mappings": { "tweet": { "properties": { "content": { "type": "text" }, "user_name": { "type": "keyword" }, "tweeted_at": { "type": "date" } } } }
}
POST _reindex
{ "source": { "index": "twitter", "type": "user" }, "dest": { "index": "users" }
}
POST _reindex
{ "source": { "index": "twitter", "type": "tweet" }, "dest": { "index": "tweets" }
}