I have an index with dynamic_templates set as follows
"dynamic_templates": [
{
"all_dynamic_as_keyword": {
"match_mapping_type": "*",
"mapping": {
"type": "keyword",
"ignore_above": 256
}
}
}
],
I later some data arrives that has new fields like:
"order_survey": {
"2. Adult Name": "N/a",
"1. Adult Name": "Someones Name",
"1. Child Name/Age": "A Childs name"
},
At that pointGET index/_mapping
shows
"order_survey": {
"properties": {
"1": {
"properties": {
" Adult Name": {
"type": "keyword",
"ignore_above": 256
},
" Child Name/Age": {
"type": "keyword",
"ignore_above": 256
}
}
},
"2": {
"properties": {
" Adult Name": {
"type": "keyword",
"ignore_above": 256
},
" Child Name/Age": {
"type": "keyword",
"ignore_above": 256
}
}
},
This has occurred because some previous, similar data worked. However some of the data returns
{
"index": {
"_index": "ticket-v8",
"_type": "doc",
"_id": "ffadc8e9-2016-1ec4-7135-9b8806d36ae0",
"status": 400,
"error": {
"type": "mapper_parsing_exception",
"reason": "failed to parse",
"caused_by": {
"type": "class_cast_exception",
"reason": "org.elasticsearch.index.mapper.KeywordFieldMapper cannot be cast to org.elasticsearch.index.mapper.ObjectMapper"
}
}
}
}
Removing the dynamic_templates
from the index fixes the problem.
I am completely confused. Once one document has been seen with a field, then that field is mapped, and dynamic_templates are no longer involved. Right? So how can the behavior of a second document with the same field be affected by dynamic_templates?
Also, even though the mapping has split "1" and "2" into their own objects, when the data is queried the document comes back:
"order_survey": {
"1. Adult Name": "An Adults name",
"1. Child Name/Age": "A childs name/9yrs. of age",
"2. Adult Name": "Another adults name"
},
I appreciate that the index design leaves a lot to be desired. I'm trying to discover why the error occurs.
Thanks,
Steven