After reading the official website documents, I found that the mapping relationship between the ES version described by most blogs and their work on removing type was wrong. Therefore, I simplified and translated the official website documents here to briefly explain why ES should remove type. And how Es removes type.

1. Why remove type?

We often use MySQL knowledge to understand some concepts of ES, such as the analogy of ES index as database, and the analogy of type as table, but this analogy is actually inaccurate. In MySQL, tables are independent of each other, each table has its own schema, each table can have the same column name, and support different types. For example, table A’s age column is TINYINT, while table B’s age column is VARCHAR (10), but in ES, table A’s age column is VARCHAR (10). Mapping definitions for fields with the same name must be consistent, because Lucene will only store one copy at the bottom.

On this basis, if more than one type is stored in an index, and these types have very few fields in common, the data will be too discrete, thus affecting the compression performance of Lucene.

2. What does ES do to remove type

Removing Type is literally a big change, so ES provides as smooth an upgrade as possible.

2.1 Elasticsearch 5.6.0

Single_type: true is used to enable the single index single type limit (an index can only support one type) by setting the index parameter index.mapping.single_type: true. This limit has been enforced since version 6.0.

2.2 Elasticsearch 6. X

In Elasticsearch 6.x, an index can only support one type, and the recommended type name is _doc (which makes it backward-compatible with 7.x in terms of the API).

In Elasticsearch 6.8, Elasticsearch introduced a parameter control type switch: Include_type_name, which defaults to true, means type is still used. When manually set to false, the API for a request to ES will no longer include type and will instead use the format PUT /{index}/_doc/{id}.

Elasticsearch 7. 2.3 x

In Elasticsearch 7.x, include_type_name is set to false by default, and the new index API format is PUT /{index}/_doc/{id} and POST {index}/_doc. It is important to note that _doc is not a type, but merely a permanent part of the API request path.

Elasticsearch 8. 2.4 x

In Elasticsearch 8.x, include_type_name has been removed, which also means that es no longer supports any custom types.

3. References

The official documentation