# ElasticSearch 导入索引时报错 Rejecting mapping update to \[xxx\] as the final mapping would have more than 1 type: \[xxx, xxx\]

**URL:** <https://www.shiqidu.com/t/topic/623>\
**Category:** 开发调优\
**Tags:** Elasticsearch\
**Created:** [2019 年8 月 6 日 11:02 UTC](https://www.shiqidu.com/t/topic/623 "2019-08-06T11:02:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2019 年8 月 6 日 11:02 UTC](https://www.shiqidu.com/t/topic/623/1 "2019-08-06T11:02:52Z")

</div>

尝试在一个 ElasticSearch 的 index 中导入多个 type 时报错，报错信息如下：

```bash
[responseCode] => 400
    [responseHeaders] => Array
        (
            [content-type] => application/json; charset=UTF-8
            [content-length] => 355
        )

    [responseBody] => Array
        (
            [error] => Array
                (
                    [root_cause] => Array
                        (
                            [0] => Array
                                (
                                    [type] => illegal_argument_exception
                                    [reason] => Rejecting mapping update to [shiqidu] as the final mapping would have more than 1 type: [discussion, article]
                                )

                        )

                    [type] => illegal_argument_exception
                    [reason] => Rejecting mapping update to [shiqidu] as the final mapping would have more than 1 type: [discussion, article]
                )

            [status] => 400
        )

```

原因：6.0的版本不允许一个 index 下面有多个 type，并且官方说是在接下来的7.0版本中会删掉 type ，[官方说明](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/removal-of-types.html#removal-of-types) ，搞得有点迷，看一些文章说 ElasticSearch 的 `index` 相当于 `数据库`，`type` 相当于 `数据表`，但是现在看来，如果要储存多个表的数据，还是得建立多个 index 索引。
