# index作成時にRejecting mapping update to \[\] as the final mapping would have more than 1 type:

**URL:** <https://discuss.elastic.co/t/index-rejecting-mapping-update-to-as-the-final-mapping-would-have-more-than-1-type/200830>\
**Category:** 日本語による質問・議論はこちら\
**Created:** [September 24, 2019, 9:24am UTC](https://discuss.elastic.co/t/index-rejecting-mapping-update-to-as-the-final-mapping-would-have-more-than-1-type/200830 "2019-09-24T09:24:42Z")\
**Posts on this page:** 7\
**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 24, 2019, 9:24am UTC](https://discuss.elastic.co/t/index-rejecting-mapping-update-to-as-the-final-mapping-would-have-more-than-1-type/200830/1 "2019-09-24T09:24:43Z")

</div>

type":"illegal\_argument\_exception","reason":"Rejecting mapping update to [index\_name] as the final mapping would have more than 1 type: [\_doc, data]"}]

のエラーでインデックスの作成までは行くのですが、データの登録ができません。  
type: [\_doc, data]のようにtypeを定めている部分というのは何を参照すればよいのでしょうか？

---

<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 24, 2019, 1:05pm UTC](https://discuss.elastic.co/t/index-rejecting-mapping-update-to-as-the-final-mapping-would-have-more-than-1-type/200830/2 "2019-09-24T13:05:30Z")

</div>

Elasticsearch 6.0から、typeは１つだけ ということになっています。

[https://www.elastic.co/guide/en/elasticsearch/reference/6.7/breaking-changes-6.0.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.7/breaking-changes-6.0.html)

以下、提示されているエラーを再現する手順を書いてみます。

```auto
# インデックスを作成
PUT forum0924

# １つめのドキュメントを登録する
POST forum0924/_doc/1
{
    "message": "test1"
}

# ２つめのドキュメントを登録する
POST forum0924/data/2
{
     "message": "test2"
}

```

このようにすると、ID=2のドキュメントを登録しようとした段階で、\_docというタイプが既にある状態なのにdataというタイプを追加しようとしたとして、エラーになります。

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Rejecting mapping update to [forum0924] as the final mapping would have more than 1 type: [_doc, data]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Rejecting mapping update to [forum0924] as the final mapping would have more than 1 type: [_doc, data]"
  },
  "status": 400
}

```

もし、curlでドキュメントを登録しようとされているのならば、{Index名}/{Type名}/{ID} という構成になっているかと思うので、Typeのところを確認いただくと良いです。  
上の例では、 \_docやdataとなっているところです。

お使いのバージョンがいくつかわかりませんが、タイプについては独自に定義せずに\_docとしておくのが良いかと思います。

エラーが起きたときの具体的な手順や環境情報がありませんでしたので、想像の範囲となりますがご参考になれば幸いです。

---

<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 25, 2019, 3:51am UTC](https://discuss.elastic.co/t/index-rejecting-mapping-update-to-as-the-final-mapping-would-have-more-than-1-type/200830/3 "2019-09-25T03:51:43Z")

</div>

こんにちは。ご回答いただき、ありがとうございます。  
エラーが起きた時の手順ですが、javascriptのプログラムでindexを作成し  
request.postメソッドでindex名/data/idという形で登録したいデータを登録していました。  
この場合1件目から指定しているtypeは「data」なのでは？と考えていますが、「\_doc」が登録されているタイミングがわかりません。

request.post({  
url: `${this.esUrl + '/' + indexName}/_doc/${id}`,  
headers: {  
'Content-type': 'application/json',  
},  
auth: {  
user: 'elastic',  
password: 'hoge',  
},  
json: data,  
})

---

<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 25, 2019, 4:11am UTC](https://discuss.elastic.co/t/index-rejecting-mapping-update-to-as-the-final-mapping-would-have-more-than-1-type/200830/4 "2019-09-25T04:11:46Z")

</div>

インデックス作成は、どのように作成されていますか？

例えば、mappingを作成するときに、\_docをつけているということはありませんか？  
以下のように作っている場合は、1件目 forum0925/data/1 でドキュメントを登録しようとした段階でエラーになります。

```auto
PUT forum0925?include_type_name=true
{
  "mappings": {
    "_doc": {
      "properties": {
        "message": { "type": "text" }
      }
    }
  }
}

```

いずれにしましても、お使いのElasticsearchのバージョン情報、どういう手順、設定でインデックスを作成し、ドキュメントを登録しようとしているのか、テストデータでも良いので共有いただく方が、スムーズに解決できる可能性が高まるかと思います。

---

<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 25, 2019, 5:19am UTC](https://discuss.elastic.co/t/index-rejecting-mapping-update-to-as-the-final-mapping-would-have-more-than-1-type/200830/5 "2019-09-25T05:19:00Z")

</div>

詳細情報の提示がなくてすみません。  
インデックス作成時は以下のmappingで作成しています。(ESのバージョンはv7.3.2)  
json: {  
settings: {  
analysis: {  
analyzer: {  
my\_kuromoji\_analyzer: {  
type: 'custom',  
tokenizer: 'ja\_tokenizer',  
},  
},  
tokenizer: {  
ja\_tokenizer: {  
type: 'kuromoji\_tokenizer',  
mode: 'normal',  
},  
},  
},  
},  
mappings: {  
properties: {  
title: { type: 'text', analyzer: 'my\_kuromoji\_analyzer' },  
prefecture: { type: 'text', analyzer: 'my\_kuromoji\_analyzer' },  
onsen: { type: 'text', analyzer: 'my\_kuromoji\_analyzer' },  
price: { type: 'long' },  
reviews: { type: 'text', analyzer: 'my\_kuromoji\_analyzer' }  
}  
}

登録しようとしているドキュメント  
{ id: '1',  
title: 'hogeホテル',  
price: '9000',  
prefecture: 'ホゲ県',  
onsen: 'ホゲ温泉',  
reviews: '4\_5'}

これらのjsonをnode.jsからrequestモジュールを使用してput,postしております。

---

<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 25, 2019, 5:56am UTC](https://discuss.elastic.co/t/index-rejecting-mapping-update-to-as-the-final-mapping-would-have-more-than-1-type/200830/6 "2019-09-25T05:56:21Z")

</div>

情報ありがとうございます。

> **[Moving from types to typeless APIs in Elasticsearch 7.0](https://www.elastic.co/jp/blog/moving-from-types-to-typeless-apis-in-elasticsearch-7-0)**
>
> Elasticsearch 7.0 deprecated APIs that accept types, introduced new typeless APIs, and removed support for the \_default\_ mapping. Learn what you can do to transition to typeless APIs, and make your upgrade an easy one.

7系からタイプ"レス"ということで、タイプを指定しなくなっています。  
内部では \_docを使うことになっているので、提示いただいた例ですとmappingやsettings情報をつけてインデックスを登録した時点で、\_docが登録されていると思います。

もし、単純にmappingやsettingsをつけずにインデックスを作成したら、typeをdataにして登録してもエラーにならないはずです。

このようなインデックス作成です。

```auto
PUT hoge-index

```

\_docで登録されるタイミングはどこか？ という点については上記のような内容になろうかと思っております。

一方、ドキュメント登録については、タイプレスの考え方に準じて、  
dataで登録しているところを \_docとしてドキュメントを登録して頂くのがよさそうに思います。

---

<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 23, 2019, 5:56am UTC](https://discuss.elastic.co/t/index-rejecting-mapping-update-to-as-the-final-mapping-would-have-more-than-1-type/200830/7 "2019-10-23T05:56:30Z")

</div>

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