# Confusion on disable automatic type creation

**URL:** <https://discuss.elastic.co/t/confusion-on-disable-automatic-type-creation/97624>\
**Category:** Elasticsearch\
**Created:** [August 18, 2017, 6:54pm UTC](https://discuss.elastic.co/t/confusion-on-disable-automatic-type-creation/97624 "2017-08-18T18:54:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cord\_thomas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cord_thomas/32/8009_2.png) [@cord\_thomas](https://discuss.elastic.co/u/cord_thomas)\
**Post date:** [August 18, 2017, 6:54pm UTC](https://discuss.elastic.co/t/confusion-on-disable-automatic-type-creation/97624/1 "2017-08-18T18:54:28Z")

</div>

I have a collection of JSON files that all together have over 1,000 fields. After a first round ingestion, I identified ~65 fields that would be interesting.

I am loading the JSON files into ES via the curl XPOST method if that matters.

I have tried to create the index with a mapping definition that starts like this, with all 65 fields:

PUT /pubsjson/\_mapping/pub  
{  
"\_all" : { "enabled" : false },  
"dynamic": false,  
"properties" : {  
"navTitle" : { "type": "text" },  
"par.product.long\_abstract" : { "type": "text" },  
...

When I try this, dynamic fields are still created.

I tried "dynamic": "strict" and others.

From [https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-mapping.html#\_disabling\_automatic\_type\_creation](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-mapping.html#_disabling_automatic_type_creation) i tried recreating my index and applied this:

PUT pubsjson/\_settings  
{  
"index.mapper.dynamic":false  
}

Yet, it still creates all the fields in the JSON file i submit.

what am I missing? Is it possible the old types are still in Elasticsearch's bowels from my first ingestion somehow? I am deleting the index each time.

I understand i could create a mapping with all 1,000+ fields and explicitly ignore those we don't want, but that doesn't scale well as these JSON will evolve over time.

---

<div class="post-metadata">

**Author:** ![jasontedor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasontedor/32/66992_2.png) [@jasontedor](https://discuss.elastic.co/u/jasontedor)\
**Post date:** [August 18, 2017, 11:23pm UTC](https://discuss.elastic.co/t/confusion-on-disable-automatic-type-creation/97624/2 "2017-08-18T23:23:50Z")

</div>

> [@cord\_thomas](#):
>
> what am I missing?

The index setting `index.mapper.dynamic` is about _types_ and you're trying to prevent new _fields_ from being added. For that, you have to use the [`dynamic` property](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/dynamic.html) for objects in the mapping:

```auto
$ curl -XPUT localhost:9200/i?pretty=true -d '
> {
> "mappings": {
> "my_type": {
> "dynamic": false,
> "properties": {
> "my_field": {
>. "type": "long"
>. }
> }
> }
> }
> }'
{
  "acknowledged" : true,
  "shards_acknowledged" : true
}

$ curl -XPOST localhost:9200/i/my_type/1?pretty=true -d '
> {
> "my_field": 123,
> "another_field": 456
> }'
{
  "_index" : "i",
  "_type" : "my_type",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "created" : true
}
$ curl -XGET localhost:9200/i/my_type/_mapping?pretty=true
{
  "i" : {
    "mappings" : {
      "my_type" : {
        "dynamic" : "false",
        "properties" : {
          "my_field" : {
            "type" : "long"
          }
        }
      }
    }
  }
}

```

The last output shows that the mapping was _not_ updated, the field `another_field` was silently ignored. You can set this to strict to reject documents that contain fields that are not in the mapping. Note that you must set `dynamic` to false for any _inner_ objects in your mapping, otherwise new fields could appear on the _inner_ objects.

Please note: `_source` will still contain the unmapped fields, they will just be ignored for indexing.

---

<div class="post-metadata">

**Author:** ![cord\_thomas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cord_thomas/32/8009_2.png) [@cord\_thomas](https://discuss.elastic.co/u/cord_thomas)\
**Post date:** [August 21, 2017, 6:45pm UTC](https://discuss.elastic.co/t/confusion-on-disable-automatic-type-creation/97624/3 "2017-08-21T18:45:38Z")

</div>

Thank you - that was my confusion - source vs index. So, now i want to see if i can ignore data in the source. I now know what to look for in my search.

---

<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:** [September 18, 2017, 6:45pm UTC](https://discuss.elastic.co/t/confusion-on-disable-automatic-type-creation/97624/4 "2017-09-18T18:45:39Z")

</div>

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