Illegal_argument_exception reject mapping update category in ES 7.6

Hi,
I have created an index in elasticsearch 7.6. The mapping is as follows:

{
  "employee_202005011710": {
    "mappings": {
      "properties": {
        "employee": {
          "properties": {
            "name": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "keyword"
                }
              },
              "analyzer": "simple"
            },
            "department": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "keyword"
                }
              },
              "analyzer": "simple"
            },
            "designation": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "keyword"
                }
              },
              "analyzer": "simple"
            }
          }
        }
      }
    }
  }
}

I have a python code that performs a bulk insert into this index. However I am getting the following error when the insert is performed:

{"_index":"employee_202005011710","_type":"employee","_id":"lZWw0XEBHjlZM_lHtKQq","status":400,"error":{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [employee_202005011710] as the final mapping would have more than 1 type: [_doc, employee]"}}}

Can someone tell me what is causing this exception?

Hello @Ketan_Chachad

If the index employee_202005011710 has been created on Elasticsearch 7.x, the default document type is _doc.

You're indexing a document providing employee as value of the _type.

Since Elasticsearch 6.x it is no more possible to have multiple types within the same index and since Elasticsearch 7.x providing the document type is deprecated and it is no more required (it defaults to _doc).

There are 2 ways to solve this:

  1. Delete the index and put the the mapping with the parameter include_type_name and continue indexing the documents using employee as document _type
PUT employee_202005011710?include_type_name
{
  "mappings": {
    "employee": { # this is the type name
      "properties": {
        "employee": { # this is the name of a field
      }
    }
  }
}
  1. Just change the indexing settings on your Python code to no more provide a custom document type or force it to _doc.

As a side note, I notice the mapping has a employee property at the root, which means all fields will be within the key employee.

Thanks a lot @Luca_Belluccini for your solutions!
I tried both solutions and they worked.
However when I created a new index with include_type_name=true, I got the following message:
#! Deprecation: [types removal] Using include_type_name in create index requests is deprecated. The parameter will be removed in the next major version.
Does this mean that going forward solution #2 (using _doc or no type) is the future ready solution?

1 Like

Exactly, not providing the _doc is the future proof solution.

1 Like

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