# Object mapping \[categories\] can't be changed from nested to non-nested

**URL:** <https://discuss.elastic.co/t/object-mapping-categories-cant-be-changed-from-nested-to-non-nested/232591>\
**Category:** Elasticsearch\
**Created:** [May 14, 2020, 9:07am UTC](https://discuss.elastic.co/t/object-mapping-categories-cant-be-changed-from-nested-to-non-nested/232591 "2020-05-14T09:07:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrey1](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@andrey1](https://discuss.elastic.co/u/andrey1)\
**Post date:** [May 14, 2020, 9:07am UTC](https://discuss.elastic.co/t/object-mapping-categories-cant-be-changed-from-nested-to-non-nested/232591/1 "2020-05-14T09:07:27Z")

</div>

Hi,  
I've got a legacy a project with old version of Elasticsearch and trying to get it working with ES 7.6.2. And encountered an error which I can't understand what is wrong. There is big index definition so I quote only parts which seem related with error.

So definition of index is:

```auto
PUT my_index
{
    "mappings": {
      "properties": {
        "categories": {
          "type": "nested",
          "properties": {
            "cpath": {
              "type": "keyword"
            },
            "data": {
              "properties": {
                "name": {
                  "type": "object"
                }
              }
            },
            "id": {
              "type": "integer"
            },
            "level": {
              "type": "integer"
            },
            "name": {
              "properties": {
                "de": {
                  "type": "text",
                  "analyzer": "german"
                },
                "en": {
                  "type": "text",
                  "analyzer": "english"
                },
                "fr": {
                  "type": "text",
                  "analyzer": "french"
                }
              }
            }
          }
        }
      }
    }
}

```

And it's object which I'm trying to add into the index:

```auto
POST my_index/product/_bulk
{"index":{"_id":324767}}
{"categories": [{"id": "16697","cpath": "16697","level": "0","name": {"en": "BlaBla","de": "BlaBla", "fr": "BlaBla"}, "data": {"name": {"en": "BlaBla", "de": "BlaBla", "fr": "BlaBla"}}}]}

```

ES returns error: illegal\_argument\_exception - object mapping [categories] can't be changed from nested to non-nested.

What can be a reason of this error and how it can be fixed? Please help.

---

<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 14, 2020, 10:03am UTC](https://discuss.elastic.co/t/object-mapping-categories-cant-be-changed-from-nested-to-non-nested/232591/2 "2020-05-14T10:03:34Z")

</div>

Welcome!

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![andrey1](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@andrey1](https://discuss.elastic.co/u/andrey1)\
**Post date:** [May 14, 2020, 11:48am UTC](https://discuss.elastic.co/t/object-mapping-categories-cant-be-changed-from-nested-to-non-nested/232591/3 "2020-05-14T11:48:04Z")

</div>

Hello,

The full script is very big because it contains tens of fields, a lot of analyzers etc. So I kept only a quote related with this error.

---

<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 14, 2020, 12:03pm UTC](https://discuss.elastic.co/t/object-mapping-categories-cant-be-changed-from-nested-to-non-nested/232591/4 "2020-05-14T12:03:49Z")

</div>

As said:

> [@dadoonet](#):
>
> Please, try to keep the example as simple as possible.

Just remove the unneeded parts.

---

<div class="post-metadata">

**Author:** ![andrey1](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@andrey1](https://discuss.elastic.co/u/andrey1)\
**Post date:** [May 14, 2020, 12:16pm UTC](https://discuss.elastic.co/t/object-mapping-categories-cant-be-changed-from-nested-to-non-nested/232591/5 "2020-05-14T12:16:21Z")

</div>

Then it's done. There is request which displays a current structure of mapping for "categories" field and request which tries to add document into the index. I think it's enough.

---

<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 14, 2020, 12:30pm UTC](https://discuss.elastic.co/t/object-mapping-categories-cant-be-changed-from-nested-to-non-nested/232591/6 "2020-05-14T12:30:50Z")

</div>

I can not just copy and paste your script to run it in Kibana dev console. As we wrote in the [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) guide, could you provide something like:

```auto
DELETE index
PUT index/_doc/1
{
  "foo": "bar"
}
GET index/_search
{
  "query": {
    "match": {
      "foo": "bar"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![andrey1](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@andrey1](https://discuss.elastic.co/u/andrey1)\
**Post date:** [May 14, 2020, 3:26pm UTC](https://discuss.elastic.co/t/object-mapping-categories-cant-be-changed-from-nested-to-non-nested/232591/7 "2020-05-14T15:26:39Z")

</div>

Ok, I corrected my requests.

---

<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 14, 2020, 4:40pm UTC](https://discuss.elastic.co/t/object-mapping-categories-cant-be-changed-from-nested-to-non-nested/232591/8 "2020-05-14T16:40:50Z")

</div>

So this script works:

```auto
DELETE my_index
PUT my_index
{
    "mappings": {
      "properties": {
        "categories": {
          "type": "nested",
          "properties": {
            "cpath": {
              "type": "keyword"
            },
            "data": {
              "properties": {
                "name": {
                  "type": "object"
                }
              }
            },
            "id": {
              "type": "integer"
            },
            "level": {
              "type": "integer"
            },
            "name": {
              "properties": {
                "de": {
                  "type": "text",
                  "analyzer": "german"
                },
                "en": {
                  "type": "text",
                  "analyzer": "english"
                },
                "fr": {
                  "type": "text",
                  "analyzer": "french"
                }
              }
            }
          }
        }
      }
    }
}

POST my_index/_bulk
{"index":{"_id":324767}}
{"categories": [{"id": "16697","cpath": "16697","level": "0","name": {"en": "BlaBla","de": "BlaBla", "fr": "BlaBla"}, "data": {"name": {"en": "BlaBla", "de": "BlaBla", "fr": "BlaBla"}}}]}

```

Please note that I removed `product` from `POST my_index/product/_bulk` as you should not use it anymore. If you want to use it, you must use `_doc` instead as this is the default type name. So `POST my_index/_doc/_bulk`.

---

<div class="post-metadata">

**Author:** ![andrey1](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@andrey1](https://discuss.elastic.co/u/andrey1)\
**Post date:** [May 14, 2020, 7:55pm UTC](https://discuss.elastic.co/t/object-mapping-categories-cant-be-changed-from-nested-to-non-nested/232591/9 "2020-05-14T19:55:00Z")

</div>

Unfortunately, this solution won't fit in my case. In my system there is indexing 4 different types of documents. Though they have the same type of fields, each document has own set of fields and, what more important, they can use the same IDs. So I need a dividing documents by types.

---

<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 14, 2020, 9:02pm UTC](https://discuss.elastic.co/t/object-mapping-categories-cant-be-changed-from-nested-to-non-nested/232591/10 "2020-05-14T21:02:08Z")

</div>

You must read this then: [https://www.elastic.co/blog/removal-of-mapping-types-elasticsearch](https://www.elastic.co/blog/removal-of-mapping-types-elasticsearch)

---

<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 11, 2020, 9:02pm UTC](https://discuss.elastic.co/t/object-mapping-categories-cant-be-changed-from-nested-to-non-nested/232591/11 "2020-06-11T21:02:10Z")

</div>

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