Hello all,
this case mainly talks about "Data Writing Failure Due to the Type of Data to Be Written Was Different from That of the Existing Data"
Applicable Version
6.5.x
Context and 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 -XPOST 'http://xxx.xxx.xxx.34:24100/test_index/test_type2/id111?pretty' -H 'Content-Type: application/json' -d' { "gcsj": "2018-10-13 02:20","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 was in the following format: http://xxx.xxx.xxx.34:24100/test_index/test_type2/id111. There were three fields except the Elasticsearch node information: 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 was added to Elasticsearch 6.X. This log information indicated that if the data was written to, the type of the index data was different from that of the existing index data. As a result, the index writing failed.
You can run the following command to check the mapping of the index, confirm the existing index type name, and check whether the type of the new data was the same as the existing type.
curl -PUT "http://xxx.xxx.xxx.34:24100/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
}
}
}
}
}
}
}
}
The preceding was an example in common mode. In security mode, run the following command:
curl -XGET --negotiate -k -u : "https://IP:HTTPPORT/test_index/_mapping?pretty"
Solution
When importing data, ensure that the data type in one index is the same.
Any solutions will be appreciated!