Duplicate field allowed in type mapping


(Ben P) #1

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.


(Mike Simos) #2

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

This will stop fields from being created dynamically.


(Ben P) #3

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).


(Mark Walkom) #4

Can you provide your mapping for this index?


(Ben P) #5
{
  "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
              }
            }
          }
        }
      }
    }
  }
}

(Ben P) #6

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


(system) #7