# Semantics: How are document\_type, mapping\_type, and mapping defined and different?

**URL:** <https://discuss.elastic.co/t/semantics-how-are-document-type-mapping-type-and-mapping-defined-and-different/231394>\
**Category:** Elasticsearch\
**Created:** [May 6, 2020, 7:21pm UTC](https://discuss.elastic.co/t/semantics-how-are-document-type-mapping-type-and-mapping-defined-and-different/231394 "2020-05-06T19:21:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aorona](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aorona/32/67827_2.png) [@aorona](https://discuss.elastic.co/u/aorona)\
**Post date:** [May 6, 2020, 7:21pm UTC](https://discuss.elastic.co/t/semantics-how-are-document-type-mapping-type-and-mapping-defined-and-different/231394/1 "2020-05-06T19:21:18Z")

</div>

I an indexing my documents with an explicit mapping that I have specified. These documents:

have a document type (\_doc): a metadata label, the type of document being indexed.  
have a mapping: Either dynamically established by ES or specified explicitly by me.  
used to have a mapping type: used to represent the type of document or entity being indexed.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 7, 2020, 1:34am UTC](https://discuss.elastic.co/t/semantics-how-are-document-type-mapping-type-and-mapping-defined-and-different/231394/2 "2020-05-07T01:34:14Z")

</div>

Could you share an example of what you're saying?

---

<div class="post-metadata">

**Author:** ![aorona](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aorona/32/67827_2.png) [@aorona](https://discuss.elastic.co/u/aorona)\
**Post date:** [May 8, 2020, 12:31am UTC](https://discuss.elastic.co/t/semantics-how-are-document-type-mapping-type-and-mapping-defined-and-different/231394/3 "2020-05-08T00:31:41Z")

</div>

Yes!

Adapted from the docs:

If I do not specify the mapping it is established dynamically by ES:

```
PUT /customer/_doc/1
     {
         "name": "John Doe"
      }

GET /customer/_doc/1

{
    "_index" : "customer",
    "_type" : "_doc",
    "_id" : "1",
    "_version" : 1,
    "_seq_no" : 26,
    "_primary_term" : 4,
    "found" : true,
      "_source" : {
        "name": "John Doe"
      }
   }

```

If I specify the field data-type for name, I am giving an explicit mapping for the index.

```
PUT customer
    {
      "mappings": {
          "properties": {
          "name": {
              "type": "text"
          }
          }
      }
    }

```

So, the mapping is either established dynamically by ES or specified (as above) explicitly by me.

If I established an explicit mapping for a document, was this known as the mapping type?

The docs discuss [removal of mapping types](https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html) and say that

> Each document had a `_type` meta-field containing the type name, and searches could be limited to one or more types by specifying the type name(s) in the URL:

```
GET twitter/user,tweet/_search
{
    "query": {
      "match": {
          "user_name": "kimchy"
        }
      }
}

```

I don't understand if the \_doc field or \_type field currently or used to be referred to as a document-type or mapping-type. I would like to understand what a document-type or mapping-type is and how they relate to how the mapping is generated for an index.

I have seen the term document-type used casually and have seen it in a legacy project, but I don't see it defined in the ES docs and so am confused as to what exactly a document-type is and if it is a synonym for the deprecated mapping-type.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 8, 2020, 12:38am UTC](https://discuss.elastic.co/t/semantics-how-are-document-type-mapping-type-and-mapping-defined-and-different/231394/4 "2020-05-08T00:38:31Z")

</div>

In your pasted example, the values of the `_type` are `user` and `tweet`.

But ignore references to anything like `_type` or document types, they are deprecated and will be removed in 8.0. `_doc` is a default we use in 7.X to get users used to this being gone, so they're similar to `user` and `tweet` as per your example.

Mapping types are field definitions. That is anything as listed in the docs - [https://www.elastic.co/guide/en/elasticsearch/reference/7.6/mapping-types.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/mapping-types.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 5, 2020, 12:47am UTC](https://discuss.elastic.co/t/semantics-how-are-document-type-mapping-type-and-mapping-defined-and-different/231394/5 "2020-06-05T00:47:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
