# Elasticsearch Dynamic template not working as required

**URL:** <https://discuss.elastic.co/t/elasticsearch-dynamic-template-not-working-as-required/126476>\
**Category:** Elasticsearch\
**Created:** [April 2, 2018, 10:59pm UTC](https://discuss.elastic.co/t/elasticsearch-dynamic-template-not-working-as-required/126476 "2018-04-02T22:59:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![silent\_phantom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/silent_phantom/32/52331_2.png) [@silent\_phantom](https://discuss.elastic.co/u/silent_phantom)\
**Post date:** [April 2, 2018, 10:59pm UTC](https://discuss.elastic.co/t/elasticsearch-dynamic-template-not-working-as-required/126476/1 "2018-04-02T22:59:14Z")

</div>

I want to have an elasticsearch schema that has some pre defined fields including an object type field. I want to have all the fields inside that object type field to be string by default.

I have the following mappings and dynamic templates while creating the index.

```
PUT myindex
{
  "mappings": {
    "doc": {
      "dynamic_templates": [
        {
          "default_string": {
            "path_match": "myObj.*",
            "match_mapping_type": "*",
            "mapping": {
              "type": "text"
            }
          }
        }],
      "properties": {
        "dummy_field_name": { "type": "text" },
        "timestamp": {
          "type": "date",
          "format": "epoch_second"
        },
        "myObj": {
          "type": "object"
        }
      }
    }
  }
}

```

But when I submit a field inside the object with a numeric value, it is not mapping that field to string.

```
curl -XPOST "http://elastic-url:8080/myindex/test" -d 
'{"dummy_field_name": "dymmy_value", "myObj":{ "filed_1": 123 , 
"field_2": "some value"}, "timestamp": 1522196333}'

```

"filed\_1" is identified as a number field. But I want it to be stored as a string type.

[Field types detected](https://i.stack.imgur.com/N30Xj.png)

---

<div class="post-metadata">

**Author:** ![Sravanthi\_N\_S\_CH](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sravanthi_n_s_ch/32/50473_2.png) [@Sravanthi\_N\_S\_CH](https://discuss.elastic.co/u/Sravanthi_N_S_CH)\
**Post date:** [April 3, 2018, 8:05am UTC](https://discuss.elastic.co/t/elasticsearch-dynamic-template-not-working-as-required/126476/2 "2018-04-03T08:05:54Z")

</div>

Can you reverify your mappings ? This works absolutely fine when I tried it locally.  
Please paste your mappings after updating a document ?

---

<div class="post-metadata">

**Author:** ![silent\_phantom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/silent_phantom/32/52331_2.png) [@silent\_phantom](https://discuss.elastic.co/u/silent_phantom)\
**Post date:** [April 3, 2018, 6:12pm UTC](https://discuss.elastic.co/t/elasticsearch-dynamic-template-not-working-as-required/126476/3 "2018-04-03T18:12:56Z")

</div>

@Sravanthi_N_S_CH do you see the filed\_1 field mapped as a text field and not numeric?

---

<div class="post-metadata">

**Author:** ![silent\_phantom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/silent_phantom/32/52331_2.png) [@silent\_phantom](https://discuss.elastic.co/u/silent_phantom)\
**Post date:** [April 3, 2018, 6:29pm UTC](https://discuss.elastic.co/t/elasticsearch-dynamic-template-not-working-as-required/126476/4 "2018-04-03T18:29:29Z")

</div>

Also what version of elasticsearch are you running? I'm on 5.5.2

---

<div class="post-metadata">

**Author:** ![Sravanthi\_N\_S\_CH](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sravanthi_n_s_ch/32/50473_2.png) [@Sravanthi\_N\_S\_CH](https://discuss.elastic.co/u/Sravanthi_N_S_CH)\
**Post date:** [April 4, 2018, 5:03am UTC](https://discuss.elastic.co/t/elasticsearch-dynamic-template-not-working-as-required/126476/5 "2018-04-04T05:03:54Z")

</div>

@silent_phantom Yes, I could see the field mapped to text.

> [@silent\_phantom](#):
>
> Also what version of elasticsearch are you running? I'm on 5.5.2

I am on 5.3

---

<div class="post-metadata">

**Author:** ![silent\_phantom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/silent_phantom/32/52331_2.png) [@silent\_phantom](https://discuss.elastic.co/u/silent_phantom)\
**Post date:** [April 4, 2018, 8:53pm UTC](https://discuss.elastic.co/t/elasticsearch-dynamic-template-not-working-as-required/126476/6 "2018-04-04T20:53:16Z")

</div>

got it to work by using the index level templates  
Also, mention "_default_" as mapping type if you want to apply to all types.

---

<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:** [May 2, 2018, 8:53pm UTC](https://discuss.elastic.co/t/elasticsearch-dynamic-template-not-working-as-required/126476/7 "2018-05-02T20:53:46Z")

</div>

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