Rejecting mapping update to [xxx] as the final mapping would have more than 1 type: [_doc, xxx]

I am using Elasticsearch 7.10.2 version.
I need to create one index,

  • Index name = device
  • _type name = device

But I am not able to create getting error.

POST device/device/169062
{
               "device_name": "DESK-0002",
               "device_ip": "1.1.1.1",
               "device_os": "Default",
               "device_status": "Online"
}

Getting below error :-

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

I tried reindex also,

POST _reindex
{
  "source": {
    "index": "device",
    "type" : "_doc"
  },
  "dest": {
    "index": "device1",
    "type" : "device"
  }
}

Getting below error :

   "failures": [
      {
         "index": "device1",
         "type": "device",
         "id": "169062",
         "cause": {
            "type": "illegal_argument_exception",
            "reason": "Rejecting mapping update to [device1] as the final mapping would have more than 1 type: [_doc, device]"
         },
         "status": 400
      }
   ]

Please anyone help me out of this issue.

in ES 7.10 ,_type doesn't work,you‘d better ensure each index has only one type called _doc

here is the doc:

Thanks for the reply. But in my local machine I am able to create different index
type. Same ES version 7.10.2v

Please find below

{
  "name" : "LPTP-565",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "GZqTHy8uReu1egwqwV0etg",
  "version" : {
    "number" : "7.10.2",
    "build_flavor" : "default",
    "build_type" : "zip",
    "build_hash" : "747e1cc71def077253878a59143c1f785afa92b9",
    "build_date" : "2021-01-13T00:42:12.435326Z",
    "build_snapshot" : false,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
{
            "_index": "device",
            "_type": "device",
            "_id": "169062",
            "_score": 1,
            "_source": {
               "device_name": "DESK-0002",
               "device_ip": "10.1.1.1",
               "device_os": "Default",
               "device_status": "Online"
            }
         }

yes,v7.10 your can do it,but each index only can have one type, int v8+ ,it will not work

In my above example, I am adding only one type. But getting below error, I don't want _doc type instead of need device.

"type": "illegal_argument_exception",
      "reason": "Rejecting mapping update to [device] as the final mapping would have more than 1 type: [_doc, device]"
   

This error means that the index device already exists and was created as having the _doc type, which is the default in version 7.X.

In version 7.X you still can create index with custom types, but you should move away from using types on index as this does not work anymore in version 8.X.

Try to create a different index and you will see that this still works.

POST new-index-name/device/169062
{
               "device_name": "DESK-0002",
               "device_ip": "1.1.1.1",
               "device_os": "Default",
               "device_status": "Online"
}

But since your device index already exists, you won't be able to add a document with a different type from _doc.

Can you run GET device/_search in Kibana Dev Tools and share the result?

POST new-index-name/device/169062
{
               "device_name": "DESK-0002",
               "device_ip": "1.1.1.1",
               "device_os": "Default",
               "device_status": "Online"
}

Result :-

{
   "error": {
      "root_cause": [
         {
            "type": "illegal_argument_exception",
            "reason": "Rejecting mapping update to [new-index-name] as the final mapping would have more than 1 type: [_doc, device]"
         }
      ],
      "type": "illegal_argument_exception",
      "reason": "Rejecting mapping update to [new-index-name] as the final mapping would have more than 1 type: [_doc, device]"
   },
   "status": 400
}

GET device/_search

Result :-

{
   "error": {
      "root_cause": [
         {
            "type": "index_not_found_exception",
            "reason": "no such index [device]",
            "resource.type": "index_or_alias",
            "resource.id": "device",
            "index_uuid": "_na_",
            "index": "device"
         }
      ],
      "type": "index_not_found_exception",
      "reason": "no such index [device]",
      "resource.type": "index_or_alias",
      "resource.id": "device",
      "index_uuid": "_na_",
      "index": "device"
   },
   "status": 404
}

Try instead with

POST new-index-name/_doc/169062

Do you have any index template that is being applied to the device index or the other indice name that you tried?

I was only able to replicate this if I have an index template created without specifying the type in the template and without using include_type_name=true when creating the template.

Without a template:

REQUEST

POST device/device/169062
{
    "device_name": "DESK-0002",
    "device_ip": "1.1.1.1",
    "device_os": "Default",
    "device_status": "Online"
}

RESPONSE

#! Deprecation: [types removal] Specifying types in document index requests is deprecated, use the typeless endpoints instead (/{index}/_doc/{id}, /{index}/_doc, or /{index}/_create/{id}).
{
  "_index" : "device",
  "_type" : "device",
  "_id" : "169062",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

WIth a template without specifying the type:

Same request as above.

RESPONSE

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

But even with this error, the indice is created, just without the document.

So GET device/_search returns:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

It's strange that it shows index not found for you.

Anyway, the best solution is to not use types as this is deprecated and was removed in version 8.

If you still want to keep using types you need to check if you have any templates being applied to the device index, and if you have you need to recreate the templates with the type.

1 Like

Thank you so much. Problem in Index Template.

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