What is dynamic mapping templates in Elasticsearch?

Answer

Dynamic mapping templates give you fine-grained control over how Elasticsearch automatically maps fields that match certain conditions, beyond the simple default dynamic mapping rules. You define an ordered list of templates in the index mapping under dynamic_templates, each specifying a match condition and the desired mapping to apply. Match conditions include match (field name pattern), match_mapping_type (the detected JSON type, e.g., "string", "long"), and path_match (dot-notation path patterns). A common use case is mapping all string fields to keyword only (disabling the default text+keyword multi-field): {"match_mapping_type": "string", "mapping": {"type": "keyword"}}. Another common template forces all fields matching *_text to use a custom analyzer. Templates are evaluated in order and the first match wins.