# Duplicate field allowed in type mapping

**URL:** <https://discuss.elastic.co/t/duplicate-field-allowed-in-type-mapping/31650>\
**Category:** Elasticsearch\
**Created:** [October 5, 2015, 4:15pm UTC](https://discuss.elastic.co/t/duplicate-field-allowed-in-type-mapping/31650 "2015-10-05T16:15:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![podollb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/podollb/32/3703_2.png) [@podollb](https://discuss.elastic.co/u/podollb)\
**Post date:** [October 5, 2015, 4:15pm UTC](https://discuss.elastic.co/t/duplicate-field-allowed-in-type-mapping/31650/1 "2015-10-05T16:15:16Z")

</div>

I'm seeing that duplicate fields (same exact name) are allowed/created in my mapping.

Background: I'm running ES 1.7.2, and I created a template that causes mappings (with a certain name, in a certain index) to have a specific field as a "double" data type. This works fine. I've tested that out. So, as documents are saved, that field is populated properly (BUT only if the field is numeric and not-quoted).

BUT, if I pass in a "2", or anything quoted, I'm seeing a duplicate field is created in my mapping (with the same exact name) with data type "string". I didn't think that was possible in ES. Is there a way to prevent that?

The reason I added the template in the first place was to force the field's data type.

---

<div class="post-metadata">

**Author:** ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)\
**Post date:** [October 5, 2015, 6:09pm UTC](https://discuss.elastic.co/t/duplicate-field-allowed-in-type-mapping/31650/2 "2015-10-05T18:09:33Z")

</div>

Hi,

In your template you should add "dynamic": "strict", see the following URL:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-dynamic-mapping.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-dynamic-mapping.html)

This will stop fields from being created dynamically.

---

<div class="post-metadata">

**Author:** ![podollb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/podollb/32/3703_2.png) [@podollb](https://discuss.elastic.co/u/podollb)\
**Post date:** [October 5, 2015, 7:11pm UTC](https://discuss.elastic.co/t/duplicate-field-allowed-in-type-mapping/31650/3 "2015-10-05T19:11:38Z")

</div>

I want fields to be created dynamically. The only catch is, for a very small subset I need to specify the data type. The template approach seems like the best way to do that (per the template docs, to do just this). But the problem I'm facing (that I'm curious, might be a bug) is that even though that works as expected, ES is allowing duplicate field names with different data types (one from the explicit data type defined for that field in the template, and one from a dynamic determination).

---

<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:** [October 5, 2015, 10:40pm UTC](https://discuss.elastic.co/t/duplicate-field-allowed-in-type-mapping/31650/4 "2015-10-05T22:40:57Z")

</div>

Can you provide your mapping for this index?

---

<div class="post-metadata">

**Author:** ![podollb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/podollb/32/3703_2.png) [@podollb](https://discuss.elastic.co/u/podollb)\
**Post date:** [October 6, 2015, 3:10am UTC](https://discuss.elastic.co/t/duplicate-field-allowed-in-type-mapping/31650/5 "2015-10-06T03:10:44Z")

</div>

```
{
  "logstash-ben" : {
    "mappings" : {
      "event-ledger" : {
        "dynamic_templates" : [ {
          "string_fields" : {
            "mapping" : {
              "index" : "analyzed",
              "omit_norms" : true,
              "type" : "string",
              "fields" : {
                "raw" : {
                  "ignore_above" : 256,
                  "index" : "not_analyzed",
                  "type" : "string"
                }
              }
            },
            "match" : "*",
            "match_mapping_type" : "string"
          }
        } ],
        "_all" : {
          "enabled" : true
        },
        "properties" : {
          "@version" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "geoip" : {
            "dynamic" : "true",
            "properties" : {
              "location" : {
                "type" : "geo_point"
              }
            }
          },
          "metric_value_number" : {
            "type" : "string",
            "norms" : {
              "enabled" : false
            },
            "fields" : {
              "raw" : {
                "type" : "string",
                "index" : "not_analyzed",
                "ignore_above" : 256
              }
            }
          },
          "metric_value_number " : {
            "type" : "double"
          },
          "name" : {
            "type" : "string",
            "norms" : {
              "enabled" : false
            },
            "fields" : {
              "raw" : {
                "type" : "string",
                "index" : "not_analyzed",
                "ignore_above" : 256
              }
            }
          }
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![podollb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/podollb/32/3703_2.png) [@podollb](https://discuss.elastic.co/u/podollb)\
**Post date:** [October 6, 2015, 3:14am UTC](https://discuss.elastic.co/t/duplicate-field-allowed-in-type-mapping/31650/6 "2015-10-06T03:14:01Z")

</div>

> [@podollb](#):
>
> "metric\_value\_number "

I think I see the problem as I'm posting this! Doh!  
I must have a typo in my template (field name).

---

<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:** [July 5, 2017, 11:46pm UTC](https://discuss.elastic.co/t/duplicate-field-allowed-in-type-mapping/31650/7 "2017-07-05T23:46:37Z")

</div>


