# Documentation for dynamic template mappings?

**URL:** <https://discuss.elastic.co/t/documentation-for-dynamic-template-mappings/311746>\
**Category:** Elasticsearch\
**Created:** [August 9, 2022, 2:18pm UTC](https://discuss.elastic.co/t/documentation-for-dynamic-template-mappings/311746 "2022-08-09T14:18:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nisow95612](https://avatars.discourse-cdn.com/v4/letter/n/3d9bf3/32.png) [@nisow95612](https://discuss.elastic.co/u/nisow95612)\
**Post date:** [August 9, 2022, 2:18pm UTC](https://discuss.elastic.co/t/documentation-for-dynamic-template-mappings/311746/1 "2022-08-09T14:18:27Z")

</div>

Hello,  
I have trouble finding API documentation for setting `dynamic templates`.

I expected this to be documented at [Update mapping API | Elasticsearch Guide [8.3] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html) , but this just points to "mapping object" (A link to [Mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)!) and [Mapping parameters](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-params.html). First is a generic page about mappings, second describes only properties of static mappings.

The same problem is with [Create or update index template API | Elasticsearch Guide [8.3] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates-v1.html), this also links just to the "mapping object" (A link to [Mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)!), [Mapping parameters](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-params.html) and [Mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html).

[Mapping | Elasticsearch Guide [8.3] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html) then links to [Dynamic mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-field-mapping.html) and [dynamic templates](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html). First describes how dynamic mappings happens by default, second documents only few select examples.

Can somebody please point me to proper documentation of API that sets dynamic mapping templates?  
Thank you!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 9, 2022, 11:59pm UTC](https://discuss.elastic.co/t/documentation-for-dynamic-template-mappings/311746/2 "2022-08-09T23:59:41Z")

</div>

If you don't set a mapping then dynamic applies by default.

Or is there something more specific you are looking to do?

---

<div class="post-metadata">

**Author:** ![nisow95612](https://avatars.discourse-cdn.com/v4/letter/n/3d9bf3/32.png) [@nisow95612](https://discuss.elastic.co/u/nisow95612)\
**Post date:** [August 10, 2022, 8:59am UTC](https://discuss.elastic.co/t/documentation-for-dynamic-template-mappings/311746/3 "2022-08-10T08:59:43Z")

</div>

Thanks for answering this quickly.

Yes, I am specifically looking for a more complete description of this `dynamic mapping templates` feature.  
The best I managed to find is [Dynamic templates | Elasticsearch Guide [8.3] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html#dynamic-templates), but it looks incomplete. For example it claims that `Dynamic templates are specified as an array of named objects:` like this:

```auto
"dynamic_templates": [
    {
      "my_template_name": { 
        ... match conditions ... 
        "mapping": { ... } 
      }
    },

```

But actually the `"mapping"` part is not mandatory at all. On the other hand there could be a `"runtime"` section that is not mentioned in the syntax (and its presence actually forbids `"mapping"` from being present). I am looking for details like this.

* * *

Well, concretely I am trying to ossify/formalize the currently known mappings without losing the agility of a fresh _ES_ installation when it comes to processing of previously unknown fields.  
I do not like `"dynamic": "enabled"`, because that does not provide an easy way for _kibana_ users to see that a field is prone to conflicts and/or changes because its type is not fixed.  
I also do not like `"dynamic":"runtime"`, because that does not provide adequate performance. The moment the users of the _kibana_ notice the new field, they will expect full performace of it.

* * *

A perfect solution would be to have `"dynamic": "enabled"` but somehow mark the dynamically added fields in a way that alerts users of _kibana_ that this field is not set in stone and may change.

For example I hoped to create a subfield _"fieldname.autodetected"_ and prevent the _"fieldname"_ field from being mapped at all (like [Mapping: trying to ignore 'field' but keeping 'field.raw'](https://discuss.elastic.co/t/mapping-trying-to-ignore-field-but-keeping-field-raw/92621) asks), but found no way to do that. I know I can make the _"fieldname"_ field unindexed, but that will both confuse the users AND occupy two slots out of the 1000-field-limit instead of one.

I could tolerate the _"fieldname"_ field being a runtime field and _"fieldname.autodetected"_ being a normal field, but I do not see any example for this either.

Thus, I was hoping somebody could point me to a more complete documentation where I could find these things.

---

<div class="post-metadata">

**Author:** ![nisow95612](https://avatars.discourse-cdn.com/v4/letter/n/3d9bf3/32.png) [@nisow95612](https://discuss.elastic.co/u/nisow95612)\
**Post date:** [August 11, 2022, 8:55am UTC](https://discuss.elastic.co/t/documentation-for-dynamic-template-mappings/311746/4 "2022-08-11T08:55:47Z")

</div>

> **I have tried blocking the original field by a script**
>
> ```auto
> {
> "new dynamic field": {
> "mapping": {
> "type": "boolean",
> "script": {
> "source": "emit(null)"
> },
> "fields": {
> "autotype": {
> "type": "{dynamic_type}"
> }
> },
> "match_mapping_type": "*"
> }
> }
> }
> 
> ```

- This does not work, it gives `Cannot define multifields on a field with a script`

> **I have tried blocking the field by setting it to boolean + ignore\_malformed**
>
> ```auto
> {
> "new dynamic field": {
> "mapping": {
> "type": "boolean",
> "ignore_malformed": "true",
> "fields": {
> "autotype": {
> "type": "{dynamic_type}"
> }
> },
> "match_mapping_type": "*"
> }
> }
> }
> 
> ```

- That is documented as unsupported and in practice it gets silently ignored

> **I have tried blocking the field by setting it to geo\_point + ignore\_malformed**
>
> ```auto
> {
> "new dynamic field": {
> "mapping": {
> "type": "geo_point",
> "ignore_malformed": "true",
> "fields": {
> "autotype": {
> "type": "{dynamic_type}"
> }
> },
> "match_mapping_type": "*"
> }
> }
> }
> 
> ```

- This is documented as supported, but in practice `ignore_malformed` does not work as expected. Indexed documents are rejected with errors like `{"type": "illegal_state_exception", "reason": "found leftover path elements: fieldname."}`

> **I had some success with ignore\_maformed + requiring a date prefixed by some klingon**
>
> ```auto
> {
> "new dynamic field": {
> "mapping": {
> "type": "date",
> "format": "'''arlogh Qoylu''''pu''''?'yyyyy.d",
> "ignore_malformed": "true",
> "fields": {
> "autotype": {
> "type": "{dynamic_type}"
> }
> },
> "match_mapping_type": "*"
> }
> }
> }
> 
> ```

- This is probably very indefficient, but it does succeed in removing the original field
- Unfortunately I forgot that _kibana_ hides multi-fields under the main field, which cause the whole field to be marked as "Ignored value" and most of GUI tools to be disabled.
- But maybe that is a good thing that these _unstable_ fields will show a warning and block filtering by default. That gives me opportunity to brief my colleagues about these fields before I show them the trick that adding the `.autotype` multi-field into "Selected fields" allows searching as usual.

EDIT1: `discover:showMultiFields` in [Advanced Settings | Kibana Guide [8.3] | Elastic](https://www.elastic.co/guide/en/kibana/current/advanced-options.html) might help with visibility of these multi-fields, but personally I'll just stick to briefing my colleagues manually.

EDIT2: I think this solution triggers a small issue in _kibana_: When value `13` gets indexed into a field configured to this _klingon date_ type, _kibana discover_ will then show the `Ignored value` warning with a value of `Jan 1, 1970 @00:00:00.013`, i.e. interprets the value `13` as unix millisecond timestamp. I think that is a bug. _Kibana_ should show this ignored value as-is, because this conversion brings no benefit and it just makes debugging the ignored value problem unnecessarily harder.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 8, 2022, 8:56am UTC](https://discuss.elastic.co/t/documentation-for-dynamic-template-mappings/311746/5 "2022-09-08T08:56:04Z")

</div>

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