# Index作成時のtype指定について

**URL:** <https://discuss.elastic.co/t/index-type/201166>\
**Category:** 日本語による質問・議論はこちら\
**Created:** [September 26, 2019, 7:25am UTC](https://discuss.elastic.co/t/index-type/201166 "2019-09-26T07:25:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Masanori\_Mishima](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/masanori_mishima/32/45030_2.png) [@Masanori\_Mishima](https://discuss.elastic.co/u/Masanori_Mishima)\
**Post date:** [September 26, 2019, 7:25am UTC](https://discuss.elastic.co/t/index-type/201166/1 "2019-09-26T07:25:24Z")

</div>

Elasticsearchはver7.0からタイプレスAPIになったということで、  
index一つに付き一つのtypeしか許容されない認識ですが、

> **[Removal of mapping types | Elasticsearch Guide \[7.0\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/removal-of-types.html#_custom_type_field)**

↑この記事のCustom type fieldの項目を読むと

> PUT twitter  
> {  
> "mappings": {  
> "user": {  
> "properties": {  
> "name": { "type": "text" },  
> "user\_name": { "type": "keyword" },  
> "email": { "type": "keyword" }  
> }  
> },  
> "tweet": {  
> "properties": {  
> "content": { "type": "text" },  
> "user\_name": { "type": "keyword" },  
> "tweeted\_at": { "type": "date" }  
> }  
> }  
> }  
> }

のようにtypeをtweetとuserの2つで設定しているように見受けられるのですが、どういうことでしょうか？  
index作成時にmappingやsettingを行う際に複数のtypeを指定していれば許容され、指定せずにindexを作成した場合は自動で内部的に扱っている\_docがindexのtypeとして適用され、以後indexに格納するデータは\_docタイプのみしか許容しなくなるということなのでしょうか？

---

<div class="post-metadata">

**Author:** ![tsgkdt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsgkdt/32/39151_2.png) [@tsgkdt](https://discuss.elastic.co/u/tsgkdt)\
**Post date:** [September 26, 2019, 12:54pm UTC](https://discuss.elastic.co/t/index-type/201166/2 "2019-09-26T12:54:42Z")

</div>

提示された箇所は、「タイプを複数利用していたとき、どのように変更できるか」の例示で  
7.xのタイプレスになる前の、 **従来の設定** を示している箇所かと思います。

> You can achieve the same thing by adding a custom `type` field as follows:

と書かれた以降が、じゃあタイプレスの7系ではどうやって書けるのか、という具体例になっています。

特に注釈１～４で示されている`You can achieve the same thing by adding a custom type field as follows:` と書かれたところですね。

ですので、タイプという概念はなくなり、\_docを使うということ、  
従来の\_typeの使い方をしたいのであれば、それを表すフィールドを１つ定義しましょうという理解で良いのではないかと思います。

---

<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:** [October 24, 2019, 12:54pm UTC](https://discuss.elastic.co/t/index-type/201166/3 "2019-10-24T12:54:42Z")

</div>

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