44IMPORTANT: Indices created in Elasticsearch 6.0.0 or later may only contain a
55single <<mapping-type,mapping type>>. Indices created in 5.x with multiple
66mapping types will continue to function as before in Elasticsearch 6.x.
7- Mapping types will be completely removed in Elasticsearch 7.0.0.
7+ Types will be deprecated in APIs in Elasticsearch 7.0.0, and completely
8+ removed in 8.0.0.
89
910[float]
1011=== What are mapping types?
@@ -161,12 +162,12 @@ You can achieve the same thing by adding a custom `type` field as follows:
161162
162163[source,js]
163164----
164- PUT twitter?include_type_name=true <1>
165+ PUT twitter
165166{
166167 "mappings": {
167168 "_doc": {
168169 "properties": {
169- "type": { "type": "keyword" }, <2 >
170+ "type": { "type": "keyword" }, <1 >
170171 "name": { "type": "text" },
171172 "user_name": { "type": "keyword" },
172173 "email": { "type": "keyword" },
@@ -204,17 +205,15 @@ GET twitter/_search
204205 },
205206 "filter": {
206207 "match": {
207- "type": "tweet" <2 >
208+ "type": "tweet" <1 >
208209 }
209210 }
210211 }
211212 }
212213}
213214----
214215// NOTCONSOLE
215- <1> Use `include_type_name=true` in case need to use the "old" syntax including the "_doc" object like
216- in this example
217- <2> The explicit `type` field takes the place of the implicit `_type` field.
216+ <1> The explicit `type` field takes the place of the implicit `_type` field.
218217
219218[float]
220219==== Parent/Child without mapping types
@@ -258,30 +257,28 @@ Elasticsearch 6.x::
258257
259258* The `_default_` mapping type is deprecated.
260259
260+ * In 6.7, the index creation, index template, and mapping APIs support a query
261+ string parameter (`include_type_name`) which indicates whether requests and
262+ responses should include a type name. It defaults to `true`, and not setting
263+ `include_type_name=false` will result in a deprecation warning. Indices which
264+ don't have an explicit type will use the dummy type name `_doc`.
265+
261266Elasticsearch 7.x::
262267
263- * The `type` parameter in URLs are deprecated. For instance, indexing
264- a document no longer requires a document `type`. The new index APIs
268+ * Specifying types in requests is deprecated. For instance, indexing a
269+ document no longer requires a document `type`. The new index APIs
265270 are `PUT {index}/_doc/{id}` in case of explicit ids and `POST {index}/_doc`
266271 for auto-generated ids.
267272
268- * The index creation, `GET|PUT _mapping` and document APIs support a query
269- string parameter (`include_type_name`) which indicates whether requests and
270- responses should include a type name. It defaults to `true`.
271- 7.x indices which don't have an explicit type will use the dummy type name
272- `_doc`. Not setting `include_type_name=false` will result in a deprecation
273- warning.
273+ * The `include_type_name` parameter in the index creation, index template,
274+ and mapping APIs will default to `false`. Setting the parameter will result
275+ in a deprecation warning.
274276
275277* The `_default_` mapping type is removed.
276278
277279Elasticsearch 8.x::
278280
279- * The `type` parameter is no longer supported in URLs.
280-
281- * The `include_type_name` parameter is deprecated, default to `false` and fails
282- the request when set to `true`.
283-
284- Elasticsearch 9.x::
281+ * Specifying types in requests is no longer supported.
285282
286283* The `include_type_name` parameter is removed.
287284
@@ -427,17 +424,26 @@ POST _reindex
427424// NOTCONSOLE
428425
429426[float]
430- === Use `include_type_name=false` to prepare for upgrade to 8 .0
427+ === Typeless APIs in 7 .0
431428
432- Index creation and mapping APIs support a new `include_type_name` url parameter
433- starting with version 6.7. It will default to `true` in version 6.7, default to
434- `false` in version 7.0 and will be removed in version 8.0. When set to `true`,
435- this parameter enables the pre-7.0 behavior of using type names in the API.
429+ In Elasticsearch 7.0, each API will support typeless requests,
430+ and specifying a type will produce a deprecation warning.
436431
437- See some examples of interactions with Elasticsearch with this option turned off:
432+ NOTE: Typeless APIs work even if the target index contains a custom type.
433+ For example, if an index has the the custom type name `my_type`, we can add
434+ documents to it using typeless `index` calls, and load documents with typeless
435+ `get` calls.
438436
439437[float]
440- ==== Index creation
438+ ==== Indices APIs
439+
440+ Index creation, index template, and mapping APIs support a new `include_type_name`
441+ url parameter that specifies whether mapping definitions in requests and responses
442+ should contain the type name. The parameter defaults to `true` in version 6.7 to
443+ match the pre-7.0 behavior of using type names in mappings. It defaults to `false`
444+ in version 7.0 and will be removed in version 8.0.
445+
446+ See some examples of interactions with Elasticsearch with this option provided:
441447
442448[source,js]
443449--------------------------------------------------
@@ -455,27 +461,27 @@ PUT index?include_type_name=false
455461// CONSOLE
456462<1> Mappings are included directly under the `mappings` key, without a type name.
457463
458- [float]
459- ==== PUT and GET mappings
460-
461464[source,js]
462465--------------------------------------------------
463- PUT index
464-
465466PUT index/_mappings?include_type_name=false
466467{
467468 "properties": { <1>
468- "foo ": {
469- "type": "keyword "
469+ "bar ": {
470+ "type": "text "
470471 }
471472 }
472473}
473-
474- GET index/_mappings?include_type_name=false
475474--------------------------------------------------
476475// CONSOLE
476+ // TEST[continued]
477477<1> Mappings are included directly under the `mappings` key, without a type name.
478478
479+ [source,js]
480+ --------------------------------------------------
481+ GET index/_mappings?include_type_name=false
482+ --------------------------------------------------
483+ // CONSOLE
484+ // TEST[continued]
479485
480486The above call returns
481487
@@ -487,6 +493,9 @@ The above call returns
487493 "properties": { <1>
488494 "foo": {
489495 "type": "keyword"
496+ },
497+ "bar": {
498+ "type": "text"
490499 }
491500 }
492501 }
@@ -499,22 +508,22 @@ The above call returns
499508[float]
500509==== Document APIs
501510
502- Index APIs must be called with the `{index}/_doc` path for automatic generation of
503- the `_id` and `{index}/_doc/{id}` with explicit ids.
511+ In 7.0, index APIs must be called with the `{index}/_doc` path for automatic
512+ generation of the `_id` and `{index}/_doc/{id}` with explicit ids.
504513
505514[source,js]
506515--------------------------------------------------
507516PUT index/_doc/1
508517{
509- "foo": "bar "
518+ "foo": "baz "
510519}
511520--------------------------------------------------
512521// CONSOLE
513522
514523[source,js]
515524--------------------------------------------------
516525{
517- "_index": "index", <1>
526+ "_index": "index",
518527 "_id": "1",
519528 "_type": "_doc",
520529 "_version": 1,
@@ -529,14 +538,98 @@ PUT index/_doc/1
529538}
530539--------------------------------------------------
531540// TESTRESPONSE
532- <1> The response does not include a `_type`.
533541
534- The <<docs-index_,GET>>, <<docs-delete,`DELETE`>>, <<docs-update,`_update`>> and <<search,`_search`>> APIs
535- will continue to return a `_type` key in the response in 7.0, but it is considered deprecated and will be
536- removed in 8.0.
542+ Similarly, the `get` and `delete` APIs use the path `{index}/_doc/{id}`:
543+
544+ [source,js]
545+ --------------------------------------------------
546+ GET index/_doc/1
547+ --------------------------------------------------
548+ // CONSOLE
549+ // TEST[continued]
550+
551+ For API paths that contain both a type and endpoint name like `_update`,
552+ in 7.0 the endpoint will immediately follow the index name:
553+
554+ [source,js]
555+ --------------------------------------------------
556+ POST index/_update/1
557+ {
558+ "doc" : {
559+ "foo" : "qux"
560+ }
561+ }
562+
563+ GET /index/_source/1
564+ --------------------------------------------------
565+ // CONSOLE
566+ // TEST[continued]
567+
568+ Types should also no longer appear in the body of requests. The following
569+ example of bulk indexing omits the type both in the URL, and in the individual
570+ bulk commands:
571+
572+ [source,js]
573+ --------------------------------------------------
574+ POST _bulk
575+ { "index" : { "_index" : "index", "_id" : "3" } }
576+ { "foo" : "baz" }
577+ { "index" : { "_index" : "index", "_id" : "4" } }
578+ { "foo" : "qux" }
579+ --------------------------------------------------
580+ // CONSOLE
581+
582+ [float]
583+ ==== Search APIs
584+
585+ When calling a search API such `_search`, `_msearch`, or `_explain`, types
586+ should not be included in the URL. Additionally, the `_type` field should not
587+ be used in queries, aggregations, or scripts.
588+
589+ [float]
590+ ==== Types in responses
591+
592+ The document and search APIs will continue to return a `_type` key in
593+ responses, to avoid breaks to response parsing. However, the key is
594+ considered deprecated and should no longer be referenced. Types will
595+ be completely removed from responses in 8.0.
596+
597+ Note that when a deprecated typed API is used, the index's mapping type will be
598+ returned as normal, but that typeless APIs will return the dummy type `_doc`
599+ in the response. For example, the following typeless `get` call will always
600+ return `_doc` as the type, even if the mapping has a custom type name like
601+ `my_type`:
602+
603+ [source,js]
604+ --------------------------------------------------
605+ PUT index/my_type/1
606+ {
607+ "foo": "baz"
608+ }
609+
610+ GET index/_doc/1
611+ --------------------------------------------------
612+ // CONSOLE
613+
614+ [source,js]
615+ --------------------------------------------------
616+ {
617+ "_index" : "index",
618+ "_type" : "_doc",
619+ "_id" : "1",
620+ "_version" : 1,
621+ "_seq_no" : 0,
622+ "_primary_term" : 1,
623+ "found": true,
624+ "_source" : {
625+ "foo" : "baz"
626+ }
627+ }
628+ --------------------------------------------------
629+ // TESTRESPONSE
537630
538631[float]
539- === Index templates
632+ ==== Index templates
540633
541634It is recommended to make index templates typeless before upgrading to 7.0 by
542635re-adding them with `include_type_name` set to `false`.
@@ -608,3 +701,16 @@ In case of implicit index creation, because of documents that get indexed in
608701an index that doesn't exist yet, the template is always honored. This is
609702usually not a problem due to the fact that typeless index calls work on typed
610703indices.
704+
705+ [float]
706+ ==== Mixed-version clusters
707+
708+ In a cluster composed of both 6.7 and 7.0 nodes, the parameter
709+ `include_type_name` should be specified in indices APIs like index
710+ creation. This is because the parameter has a different default between
711+ 6.7 and 7.0, so the same mapping definition will not be valid for both
712+ node versions.
713+
714+ Typeless document APIs such as `bulk` and `update` are only available as of
715+ 7.0, and will not work with 6.7 nodes. This also holds true for the typeless
716+ versions of queries that perform document lookups, such as `terms`.
0 commit comments