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.
Previous
What is the multi-search (msearch) API in Elasticsearch?
Next
What are cluster health states in Elasticsearch and what causes each?
More Elasticsearch Questions
View all →- Intermediate What is the difference between query context and filter context in Elasticsearch?
- Intermediate What is a bool query in Elasticsearch?
- Intermediate What are aggregations in Elasticsearch?
- Intermediate What is the difference between text and keyword field types?
- Intermediate What are index templates and component templates in Elasticsearch?