I get the following error when using dynamic_templates, I'd like to map the fields with k8s.* as text and nested object field "network" as a flat_object.
I've tried using both regex and path_match but get the same error.
Can anyone let me know if I'm doing it correctly?
Configuration:
PUT _index_template/test_logs
{
"index_patterns": [
"test_*"
],
"template": {
"mappings": {
"dynamic_templates": [
{
"k8s_fields_as_text": {
"match_pattern": "regex",
"match": "^k8s.*",
"mapping": {
"type": "text"
}
}
},
{
"nested_object_fields_as_flat_object": {
"match": "*",
"match_mapping_type": "object",
"mapping": {
"type": "flat_object"
}
}
}
]
}
}
}
PUT test_logs/_doc/1
{
"k8s.application.name": "test-app",
"k8s.container.restart_count": "0",
"k8s.namespace.name": "test",
"k8s.pod.name": "test-app-9f45bf4b-v76fr",
"network": {
"ip_address": "10.10.1.15",
"security_group_id": "sg-111111111111111",
"subnet_id": "subnet-111111111111111",
"vpc_id": "vpc-111111111111111"
}
}
Error:
{
"error": {
"root_cause": [
{
"type": "class_cast_exception",
"reason": "class_cast_exception: class org.opensearch.index.mapper.TextFieldMapper cannot be cast to class org.opensearch.index.mapper.ObjectMapper (org.opensearch.index.mapper.TextFieldMapper and org.opensearch.index.mapper.ObjectMapper are in unnamed module of loader 'app')"
}
],
"type": "mapper_parsing_exception",
"reason": "failed to parse",
"caused_by": {
"type": "class_cast_exception",
"reason": "class_cast_exception: class org.opensearch.index.mapper.TextFieldMapper cannot be cast to class org.opensearch.index.mapper.ObjectMapper (org.opensearch.index.mapper.TextFieldMapper and org.opensearch.index.mapper.ObjectMapper are in unnamed module of loader 'app')"
}
},
"status": 400
}
Note: I'm using OpenSearch 2.11 and they don't have documentation on dynamic_templates hence I've raised a topic here.