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

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:

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:

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.

Welcome!

Could you provide a full recreation script as described in About the Elasticsearch category. 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.

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.

As said:

Just remove the unneeded parts.

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.

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 guide, could you provide something like:

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

Ok, I corrected my requests.

So this script works:

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.

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.

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

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