# Dynamic\_templates are not working as expected

**URL:** <https://discuss.elastic.co/t/dynamic-templates-are-not-working-as-expected/258193>\
**Category:** Elasticsearch\
**Created:** [December 9, 2020, 9:53pm UTC](https://discuss.elastic.co/t/dynamic-templates-are-not-working-as-expected/258193 "2020-12-09T21:53:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liat](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/liat/32/48089_2.png) [@Liat](https://discuss.elastic.co/u/Liat)\
**Post date:** [December 9, 2020, 9:53pm UTC](https://discuss.elastic.co/t/dynamic-templates-are-not-working-as-expected/258193/1 "2020-12-09T21:53:06Z")

</div>

I am trying ot have dynamic mapping for these objects:

```auto
{
participant_1{
 "role" : "role1"
},
participant_2{
 "role" : "role2"
}.

participant_3{
 "role" : "role3"
}

}

```

My mapping looks like that:

```auto
 "mappings": {
            "dynamic_templates": [
                {
                    "role_test": {
                        "match": "participant_*.role",
                        "match_pattern": "regex",
                        "mapping": {
                            "type": "keyword"
                        }
                    }
                }
            ]

```

I expect the role field to be mapped as "keyword"  
but it is actually mapped as text:

```auto
  "role": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        }

```

what am I missing?

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [December 9, 2020, 10:25pm UTC](https://discuss.elastic.co/t/dynamic-templates-are-not-working-as-expected/258193/2 "2020-12-09T22:25:42Z")

</div>

@Liat Welcome to the community!

Use `path_match` vs `match`

```auto
PUT test
{
  "mappings": {
    "dynamic_templates": [
      {
        "role_test": {
          "path_match": "participant_*.role",
          "mapping": {
            "type": "keyword"
          }
        }
      }
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![Liat](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/liat/32/48089_2.png) [@Liat](https://discuss.elastic.co/u/Liat)\
**Post date:** [December 16, 2020, 6:54pm UTC](https://discuss.elastic.co/t/dynamic-templates-are-not-working-as-expected/258193/3 "2020-12-16T18:54:01Z")

</div>

thanks! it worked 🙂

---

<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:** [January 13, 2021, 6:54pm UTC](https://discuss.elastic.co/t/dynamic-templates-are-not-working-as-expected/258193/4 "2021-01-13T18:54:38Z")

</div>

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