# Dynamic mapping strict to true

**URL:** <https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912>\
**Category:** Elasticsearch\
**Created:** [April 12, 2021, 4:10pm UTC](https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912 "2021-04-12T16:10:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [April 12, 2021, 4:10pm UTC](https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912/1 "2021-04-12T16:10:03Z")

</div>

I have a index template that I define with strict dynamic mapping.

Now I would like to add a field I have remove template, recreated with dynamic=true but it still gives me error on adding field

'error': {'type': 'strict\_dynamic\_mapping\_exception', 'reason': 'mapping set to strict, dynamic introduction of [field1] within [\_doc] is not allowed'},

But when I go to kibana and check index template it is set to dynamic=true.

it does gives me same error even when I don't have any template set (when I remove it)

how do I add a field?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 12, 2021, 9:41pm UTC](https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912/2 "2021-04-12T21:41:27Z")

</div>

It'd be useful if you could share an example to replicate what you are seeing.

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [April 13, 2021, 11:56am UTC](https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912/3 "2021-04-13T11:56:08Z")

</div>

First I created index pattern with this

```
PUT _index_template/hou_jobs
{
  "index_patterns": ["hou_jobs-*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas" : "1"
    },
    "mappings": {
      "dynamic": "strict",
      "properties": {
        "@timestamp": {
          "type": "date"
        },
        "elm": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "job": {
          "type": "long"
        },

```

Then I am trying to add a field called field1 but it won't allow.  
hence I did two different test. first remove this mapping and it give me above error.  
then I did create mapping again with dynamic=true and added this field1 in to mix.  
it still gives me same error

```
PUT _index_template/hou_vpmh_jobs_elm
{
  "index_patterns": ["hou_vpmh_jobs_elm-*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas" : "1"
    },
    "mappings": {
      "dynamic": "true",
      "properties": {
        "@timestamp": {
          "type": "date"
        },
        "elm": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "job": {
          "type": "long"
        },
        "field1:{
           "type": "boolean"
         },
```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 14, 2021, 12:04am UTC](https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912/4 "2021-04-14T00:04:22Z")

</div>

Here's what I did;

```auto
PUT test
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": "1"
  },
  "mappings": {
    "dynamic": "true",
    "properties": {
      "@timestamp": {
        "type": "date"
      },
      "number": {
        "type": "long"
      },
      "word": {
        "type": "keyword"
      }
    }
  }
}

```

And then to test it;

```auto
POST test/_doc/1
{
  "number": 5,
  "word": "test",
  "extrafield": "yes"
}

```

```auto
{
  "_index" : "test",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

```

I can't seem to replicate what you are seeing with this.

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [April 14, 2021, 1:28pm UTC](https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912/5 "2021-04-14T13:28:47Z")

</div>

Sorry I might not have explain properly  
I am talking about creating template

Here is exactly what happens. using your example. it must be some bug or I am doing something wrong

Works - Created template

```
PUT _index_template/test
{
  "index_patterns": ["test*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": "1"
    },
  "mappings": {
    "dynamic": "strict",
    "properties": {
      "@timestamp": {
        "type": "date"
      },
      "number": {
        "type": "long"
      },
      "word": {
        "type": "keyword"
      }
    }
  }
}
}

```

Works - Put one record to index

```
POST test/_doc/1
{
  "number": 5,
  "word": "test"
}

```

Failed as it suppose to fail, because I don't have extrafield define.  
works as expected

```
POST test/_doc/1
{
  "number": 5,
  "word": "test",
  "extrafield": "yes"
}

```

Now change template to dynamic=true, and added new field called extrafield

```
PUT _index_template/test
{
  "index_patterns": ["test*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": "1"
    },
  "mappings": {
    "dynamic": "true",
    "properties": {
      "@timestamp": {
        "type": "date"
      },
      "number": {
        "type": "long"
      },
      "word": {
        "type": "keyword"
      },
      **"extrafield"** :{
        "type": "boolean"
      }
    }
  }
}
}

```

This should work Right? because I have extrafield define and mapping dynamic = true but it fails

```
POST test/_doc/1
{
  "number": 5,
  "word": "test",
  "extrafield": "yes"
}

```

ERROR, Even though dynamic=true.

```
GET _index_template/test --> this tells me dynamic=true

{
  "error" : {
    "root_cause" : [
      {
        "type" : "strict_dynamic_mapping_exception",
        "reason" : "mapping set to strict, dynamic introduction of [extrafield] within [_doc] is not allowed"
      }
    ],
    "type" : "strict_dynamic_mapping_exception",
    "reason" : "mapping set to strict, dynamic introduction of [extrafield] within [_doc] is not allowed"
  },
  "status" : 400
}
```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 14, 2021, 9:08pm UTC](https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912/6 "2021-04-14T21:08:49Z")

</div>

I just did the same thing, but added a `DELETE _index_template/test` before I put the second template, and it worked fine.

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [April 14, 2021, 9:26pm UTC](https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912/7 "2021-04-14T21:26:10Z")

</div>

it is so weired I still get same failed result.

I am using 7.12.0

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [April 14, 2021, 9:36pm UTC](https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912/8 "2021-04-14T21:36:56Z")

</div>

Also test on 7.10.2 and same here is exact sequence

```
GET _index_template/test

GET test/_search

PUT _index_template/test
{
  "index_patterns": ["test*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": "1"
    },
  "mappings": {
    "dynamic": "strict",
    "properties": {
      "@timestamp": {
        "type": "date"
      },
      "number": {
        "type": "long"
      },
      "word": {
        "type": "keyword"
      }
    }
  }
}
}

POST test/_doc/1
{
  "number": 5,
  "word": "test"
  
}

DELETE _index_template/test

PUT _index_template/test
{
  "index_patterns": ["test*"],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": "1"
    },
  "mappings": {
    "dynamic": "true",
    "properties": {
      "@timestamp": {
        "type": "date"
      },
      "number": {
        "type": "long"
      },
      "word": {
        "type": "keyword"
      },
      "extrafield":{
        "type": "keyword"
      }
    }
  }
}
}

```

# Failed

```
POST test/_doc/2
{
  "number": 6,
  "word": "test1",
  "extrafield": "test5"
}

```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 14, 2021, 9:38pm UTC](https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912/9 "2021-04-14T21:38:38Z")

</div>

I jut tried and it worked fine.  
I don't have 7.10, but 7.12 works.

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [April 14, 2021, 9:40pm UTC](https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912/10 "2021-04-14T21:40:49Z")

</div>

is this relate to this issue?  
but again 7.10.2 cluster I have not run any upgrade yet.

> <https://github.com/elastic/kibana/issues/35061>
>
> Kibana version: 7.0.0
> Elasticsearch version: 7.0.0
> Server OS version: Centos 7.6 64 bit
> Browser version: Chrome Version 73.0.3683.86 (Official Build) (64-bit)
> (tried with IE also)
> Browser...

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [April 14, 2021, 9:41pm UTC](https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912/11 "2021-04-14T21:41:30Z")

</div>

> [@warkolm](#):
>
> I don't have 7.10, but 7.12 works.

I also test this on fresh 7.12 install and one with upgrade install. both same error. hmm..

---

<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 12, 2021, 9:42pm UTC](https://discuss.elastic.co/t/dynamic-mapping-strict-to-true/269912/12 "2021-05-12T21:42:26Z")

</div>

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