🏡 Home 📖 Chapter Home 👉 Next
⚡ ElasticsearchBook is crafted by Jozef Sorocin (🟢 Book a consulting hour) and powered by:
with potentially lots of currently unknown attrs.* sub-objects.
I want to map all attrs.*.created_at fields as timestamps and the rest (attrs.*.*) as keywords.
At the same time, I want to set index: false on everything else inside attrs to not make it searchable.
Let's use dynamic_templates with path_match and path_unmatch.
attrs.* objects and some other unused attributesGET myindex/_mapping<aside>
⚠️ While the above solution works perfectly fine, dynamic_templates tend to monkey-patch the underlying issue of not being able to clearly define an index's mapping.
On the other hand, there are situations where hard-coding the full mapping is not only onerous, but also impractical, and dynamic_templates do come in handy!
While wildcard attribute paths are supported in dynamic_templates, they are not in other parts of the Elasticsearch API such as aggregations. In practical terms this means that aggregating attrs.*.payload is not possible unless you resort to 6. (Painless) Scripting.
</aside>
<aside> 🔗 The official documentation is available here.
</aside>