Elasticsearch Dynamic template not working as required

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

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

@Sravanthi_N_S_CH do you see the filed_1 field mapped as a text field and not numeric?

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

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

I am on 5.3

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

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