Text field storing both String & Integer datatypes

Hi,

By accident (probably a wrong update script), I now have some text fields in my index that contain both Integers and Strings.

My Mapping looks like this:

"Test": {
"properties": {
"Status": {
"properties": {
"Code": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"Desc": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"LastUpdateTime": {
"type": "date"
}
}
}
}
}

Depending on how the data got sent (through PUT api or updated via a script, the results now look like this:

{
"_index": "test_case",
"_type": "test_case",
"_id": "1",
"_score": 0.057158414,
"_source": {
"Test": {
"Status": {
"Code": 0
}
}
}
},
{
"_index": "test_case",
"_type": "test_case",
"_id": "2",
"_score": 0.057158414,
"_source": {
"Test": {
"Status": {
"Code": "0"
}
}
}
}

Note the difference in quiotes around the Zero value of the Test.Status.Code field.

I have two options here:
Blindly update all fields via a script and set the value properly. This would cause a lot of overhead though since some exports are sent to other systems.

Only update the records that have the wrong datatype (should all be string).

I've noted some other usesr having the same issue for when the field is defined as an integer:
https://discuss.elastic.co/t/strings-in-integer-fields/58301/5

However, Coerce is not an option for text fields.

---> How can I solve this without resorting to a mass update?
---> Shouldn't this realistically throw an error or warning?

1 Like

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