# Help with using dynamic template

**URL:** <https://discuss.elastic.co/t/help-with-using-dynamic-template/353054>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [February 12, 2024, 10:29am UTC](https://discuss.elastic.co/t/help-with-using-dynamic-template/353054 "2024-02-12T10:29:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharath\_G](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sharath_g/32/123759_2.png) [@Sharath\_G](https://discuss.elastic.co/u/Sharath_G)\
**Post date:** [February 12, 2024, 10:29am UTC](https://discuss.elastic.co/t/help-with-using-dynamic-template/353054/1 "2024-02-12T10:29:58Z")

</div>

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** :

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

```

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

```

Error:

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

```

Note: I'm using OpenSearch 2.11 and they don't have documentation on dynamic\_templates hence I've raised a topic here.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 12, 2024, 10:29am UTC](https://discuss.elastic.co/t/help-with-using-dynamic-template/353054/2 "2024-02-12T10:29:59Z")

</div>

OpenSearch/OpenDistro are AWS run products and differ from the original Elasticsearch and Kibana products that Elastic builds and maintains. You may need to contact them directly for further assistance.

(This is an automated response from your friendly Elastic bot. Please report this post if you have any suggestions or concerns :elasticheart: )

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [February 12, 2024, 12:38pm UTC](https://discuss.elastic.co/t/help-with-using-dynamic-template/353054/3 "2024-02-12T12:38:22Z")

</div>

> [@Sharath\_G](#):
>
> I'm using OpenSearch 2.11 and they don't have documentation on dynamic\_templates hence I've raised a topic here.

Opensearch is not supported here, you will need to direct this question to an Opensearch forum.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 11, 2024, 12:39pm UTC](https://discuss.elastic.co/t/help-with-using-dynamic-template/353054/4 "2024-03-11T12:39:22Z")

</div>

Closed on March 11, 2024, 12:39pm UTC

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