Including dynamic templates for the elastic index

Hello everyone,

I have an elastic index with the mappings set to strict except for one field which is dynamic. I would also like to set the mapping of the dynamic field using dynamic templates

PUT trial
{
   "mappings": {
      "dynamic": "strict",
      "properties": {
         "field1": {
            "type": "nested",
            "properties": {
               "display": {
                  "type": "keyword",
                  "index": "true"
               }
            }
         },
         "customFields": {
            "dynamic": true,
            "properties": {}
         }
      },
      "dynamic_templates": [
         {
            "customFields": {
               "match": "customFields",
               "mapping": {
                  "type": "text",
                  "index": "true"
               }
            }
         }
      ]
   }
}

Once I try to index the data in this index, it looks like the dynamic template is not applied

 "customFields": { - 
          "dynamic": "true",
          "properties": { - 
            "countries": { - 
              "type": "text",
              "fields": { - 
                "keyword": { - 
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            } 
         }
       }

I am missing something in here, but cannot find out what. Many thanks!

You cannot mix strict and dynamic like that sorry to say.

Thanks @warkolm for your inputs. So I guess the only way is to use the default mapping for dynamic field, i.e, allow the customFields to be indexed as both text and keyword.

Yep.

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