Help Center/ MapReduce Service/ Component Operation Guide (LTS) (Ankara Region)/ Using Elasticsearch/ Common Issues About Elasticsearch/ What Can I Do If Data Fails to Be Written Because the Type of the Data to Be Written Is Different from That of the Existing Data?
Updated on 2024-11-29 GMT+08:00

What Can I Do If Data Fails to Be Written Because the Type of the Data to Be Written Is Different from That of the Existing Data?

Symptom

The client failed to write data, and the error message "illegal_argument_exception, final mapping would have more than 1 type" was displayed.

curl -XGET --tlsv1.2 --negotiate -k  -u :  "https://ip:httpport/test_index/test_type2/id111?pretty" -H 'Content-Type: application/json' -d' { "gcsj": "2018-10-13 10:20:05","bh": "2fdc8d48-45d5-46c3-8550-de4400a87c1c"}'
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "Rejecting mapping update to [test_index] as the final mapping would have more than 1 type: [test_type1, test_type2]"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "Rejecting mapping update to [test_index] as the final mapping would have more than 1 type: [test_type1, test_type2]"
  },
  "status" : 400
}

Cause Analysis

The data to be written is in the https://ip:httpport/test_index/test_type2/id111 format. There are three fields except the Elasticsearch node information, including index (for example, test_index), type (for example, test_type), and ID (for example, id111). The kernel constraint that data in an index can have only one data type is added to Elasticsearch 6.X. This log information indicates that if the data is written, the type of the index data is different from that of the existing index data. As a result, the index writing fails.

You can run required commands to check the mapping of the index, confirm the existing index type name, and check whether the type of the new data is the same as that of the existing type.

curl -XGET --tlsv1.2 --negotiate -k  -u :  "https://ip:httpport/test_index/_mapping?pretty"
{
  "test_index" : {
    "mappings" : {
      "test_type1" : {
        "properties" : {
          "date" : {
            "type" : "date",
            "format" : "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis"
          },
          "text" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
      }
    }
  }
}

Solution

When importing data, ensure that the data type in one index is the same.