# Issue with using dynamic templates

**URL:** https://forum.opensearch.org/t/issue-with-using-dynamic-templates/17807
**Category:** OpenSearch
**Created:** [February 8, 2024, 6:24am UTC](https://forum.opensearch.org/t/issue-with-using-dynamic-templates/17807 "2024-02-08T06:24:51Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![sharathg](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sharathg](https://forum.opensearch.org/u/sharathg)
#### Post date: [February 8, 2024, 6:24am UTC](https://forum.opensearch.org/t/issue-with-using-dynamic-templates/17807/1 "2024-02-08T06:24:51Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):  
AWS Opensearch 2.11

**Describe the issue** :

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,

```auto
{
  "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
}

```

**Configuration** :

```auto
PUT _index_template/test_logs
{
  "index_patterns": [
    "test_*"
  ],
  "template": {
    "mappings": {
      "dynamic_templates": [
        {
          "k8s_fields": {
            "match_pattern": "regex",
            "match": "^k8s.*",
            "mapping": {
              "type": "text"
            }
          }
        },
        {
          "nested_object_fields": {
            "match": "*",
            "match_mapping_type": "object",
            "mapping": {
              "type": "flat_object"
            }
          }
        }        
      ]   
    }
  }
}

```

```auto
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"
  }
}

```

Is something wrong with the regex pattern in the dynamic template?

**Relevant Logs or Screenshots** :
