Dynamic_templates are not working as expected

I am trying ot have dynamic mapping for these objects:

{
participant_1{
 "role" : "role1"
},
participant_2{
 "role" : "role2"
}.

participant_3{
 "role" : "role3"
}

}

My mapping looks like that:

 "mappings": {
            "dynamic_templates": [
                {
                    "role_test": {
                        "match": "participant_*.role",
                        "match_pattern": "regex",
                        "mapping": {
                            "type": "keyword"
                        }
                    }
                }
            ]

I expect the role field to be mapped as "keyword"
but it is actually mapped as text:

  "role": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        }

what am I missing?

@Liat Welcome to the community!

Use path_match vs match

PUT test
{
  "mappings": {
    "dynamic_templates": [
      {
        "role_test": {
          "path_match": "participant_*.role",
          "mapping": {
            "type": "keyword"
          }
        }
      }
    ]
  }
}
1 Like

thanks! it worked :slight_smile:

1 Like

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