# Several matching dynamic\_templates?

**URL:** https://discuss.elastic.co/t/several-matching-dynamic-templates/5007
**Category:** Elasticsearch
**Created:** [July 31, 2011, 2:16pm UTC](https://discuss.elastic.co/t/several-matching-dynamic-templates/5007 "2011-07-31T14:16:44Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Joel\_Abrahamsson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joel_abrahamsson/32/1924_2.png) [@Joel\_Abrahamsson](https://discuss.elastic.co/u/Joel_Abrahamsson)
#### Post date: [July 31, 2011, 2:16pm UTC](https://discuss.elastic.co/t/several-matching-dynamic-templates/5007/1 "2011-07-31T14:16:44Z")

</div>

Is it possible to somehow configure dynamic\_templates so that multiple  
matching templates will be applied? It seems to me that only the first  
matching template is used. I can see why that is, but if there's a  
workaround I'd love to know about it 🙂

As an example, I'm using something like the dynamic templates below  
and would like strings to be mapped both as multifield and as not  
included in all IF their names end with "!inall".

{  
"string\_template":{  
"match":"_",  
"match\_mapping\_type":"string",  
"mapping":{  
"type":"multi\_field",  
"fields":{  
"{name}":{  
"type":"string",  
"index":"not\_analyzed"  
},  
"standard":{  
"type":"string"  
}  
}  
}  
}  
},  
{  
"not\_in\_all\_template":{  
"match":"_!inall",  
"mapping":{  
"include\_in\_all":false  
}  
}  
},

---

<div class="post-metadata">

### Author: ![Matthew\_A\_Brown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_a_brown/32/2699_2.png) [@Matthew\_A\_Brown](https://discuss.elastic.co/u/Matthew_A_Brown)
#### Post date: [July 31, 2011, 2:23pm UTC](https://discuss.elastic.co/t/several-matching-dynamic-templates/5007/2 "2011-07-31T14:23:51Z")

</div>

Hi Joel,

Multiple matching templates are supported by ES (see the end of  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-templates.html)).  
It looks like you don't have a parallel structure between your two  
mappings, though -- did you intend to put the 'include\_in\_all' key  
inside a field definition?

Mat

On Sun, Jul 31, 2011 at 10:16, Joel Abrahamsson  
[mail@joelabrahamsson.com](mailto:mail@joelabrahamsson.com) wrote:

> Is it possible to somehow configure dynamic\_templates so that multiple  
> matching templates will be applied? It seems to me that only the first  
> matching template is used. I can see why that is, but if there's a  
> workaround I'd love to know about it 🙂
> 
> As an example, I'm using something like the dynamic templates below  
> and would like strings to be mapped both as multifield and as not  
> included in all IF their names end with "!inall".
> 
> {  
> "string\_template":{  
> "match":"_",  
> "match\_mapping\_type":"string",  
> "mapping":{  
> "type":"multi\_field",  
> "fields":{  
> "{name}":{  
> "type":"string",  
> "index":"not\_analyzed"  
> },  
> "standard":{  
> "type":"string"  
> }  
> }  
> }  
> }  
> },  
> {  
> "not\_in\_all\_template":{  
> "match":"_!inall",  
> "mapping":{  
> "include\_in\_all":false  
> }  
> }  
> },

---

<div class="post-metadata">

### Author: ![Joel\_Abrahamsson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joel_abrahamsson/32/1924_2.png) [@Joel\_Abrahamsson](https://discuss.elastic.co/u/Joel_Abrahamsson)
#### Post date: [July 31, 2011, 2:58pm UTC](https://discuss.elastic.co/t/several-matching-dynamic-templates/5007/3 "2011-07-31T14:58:40Z")

</div>

Hey!

Thanks for the reply!

I'm not sure what you mean by parallel structure? The last template is  
applied if I remove the first, otherwise the first but not the second  
is applied.

I should probably add that I'm using these for the _default_ type in a  
default-mapping.json file.

/Joel

On 31 Juli, 16:23, "Matthew A. Brown" [mat.a.br...@gmail.com](mailto:mat.a.br...@gmail.com) wrote:

> Hi Joel,
> 
> Multiple matching templates are supported by ES (see the end ofhttp://www.elasticsearch.org/guide/reference/api/admin-indices-templa...).  
> It looks like you don't have a parallel structure between your two  
> mappings, though -- did you intend to put the 'include\_in\_all' key  
> inside a field definition?
> 
> Mat
> 
> On Sun, Jul 31, 2011 at 10:16, Joel Abrahamsson
> 
> [m...@joelabrahamsson.com](mailto:m...@joelabrahamsson.com) wrote:
> 
> > Is it possible to somehow configure dynamic\_templates so that multiple  
> > matching templates will be applied? It seems to me that only the first  
> > matching template is used. I can see why that is, but if there's a  
> > workaround I'd love to know about it 🙂
> 
> > As an example, I'm using something like the dynamic templates below  
> > and would like strings to be mapped both as multifield and as not  
> > included in all IF their names end with "!inall".
> 
> > {  
> > "string\_template":{  
> > "match":"_",  
> > "match\_mapping\_type":"string",  
> > "mapping":{  
> > "type":"multi\_field",  
> > "fields":{  
> > "{name}":{  
> > "type":"string",  
> > "index":"not\_analyzed"  
> > },  
> > "standard":{  
> > "type":"string"  
> > }  
> > }  
> > }  
> > }  
> > },  
> > {  
> > "not\_in\_all\_template":{  
> > "match":"_!inall",  
> > "mapping":{  
> > "include\_in\_all":false  
> > }  
> > }  
> > },

---

<div class="post-metadata">

### Author: ![Joel\_Abrahamsson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joel_abrahamsson/32/1924_2.png) [@Joel\_Abrahamsson](https://discuss.elastic.co/u/Joel_Abrahamsson)
#### Post date: [July 31, 2011, 3:00pm UTC](https://discuss.elastic.co/t/several-matching-dynamic-templates/5007/4 "2011-07-31T15:00:15Z")

</div>

Oh, actually it seems we we're talking about different things. I'm not  
talking about index templates by dynamic templates for types/  
properties 🙂

On 31 Juli, 16:23, "Matthew A. Brown" [mat.a.br...@gmail.com](mailto:mat.a.br...@gmail.com) wrote:

> Hi Joel,
> 
> Multiple matching templates are supported by ES (see the end ofhttp://www.elasticsearch.org/guide/reference/api/admin-indices-templa...).  
> It looks like you don't have a parallel structure between your two  
> mappings, though -- did you intend to put the 'include\_in\_all' key  
> inside a field definition?
> 
> Mat
> 
> On Sun, Jul 31, 2011 at 10:16, Joel Abrahamsson
> 
> [m...@joelabrahamsson.com](mailto:m...@joelabrahamsson.com) wrote:
> 
> > Is it possible to somehow configure dynamic\_templates so that multiple  
> > matching templates will be applied? It seems to me that only the first  
> > matching template is used. I can see why that is, but if there's a  
> > workaround I'd love to know about it 🙂
> 
> > As an example, I'm using something like the dynamic templates below  
> > and would like strings to be mapped both as multifield and as not  
> > included in all IF their names end with "!inall".
> 
> > {  
> > "string\_template":{  
> > "match":"_",  
> > "match\_mapping\_type":"string",  
> > "mapping":{  
> > "type":"multi\_field",  
> > "fields":{  
> > "{name}":{  
> > "type":"string",  
> > "index":"not\_analyzed"  
> > },  
> > "standard":{  
> > "type":"string"  
> > }  
> > }  
> > }  
> > }  
> > },  
> > {  
> > "not\_in\_all\_template":{  
> > "match":"_!inall",  
> > "mapping":{  
> > "include\_in\_all":false  
> > }  
> > }  
> > },

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [July 31, 2011, 3:04pm UTC](https://discuss.elastic.co/t/several-matching-dynamic-templates/5007/5 "2011-07-31T15:04:51Z")

</div>

There isn't support in dynamic templates to "aggregate templates", the first  
one matches (ordered) will be used, so you need to provide full mapping on  
relevant ones. Its a bit tricky (at least in the way its implemented  
currently) to apply everything the matches to the new field mapping  
introduced.

On Sun, Jul 31, 2011 at 6:00 PM, Joel Abrahamsson  
[mail@joelabrahamsson.com](mailto:mail@joelabrahamsson.com)wrote:

> Oh, actually it seems we we're talking about different things. I'm not  
> talking about index templates by dynamic templates for types/  
> properties 🙂
> 
> On 31 Juli, 16:23, "Matthew A. Brown" [mat.a.br...@gmail.com](mailto:mat.a.br...@gmail.com) wrote:
> 
> > Hi Joel,
> > 
> > Multiple matching templates are supported by ES (see the end ofhttp://  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-templa)...).  
> > It looks like you don't have a parallel structure between your two  
> > mappings, though -- did you intend to put the 'include\_in\_all' key  
> > inside a field definition?
> > 
> > Mat
> > 
> > On Sun, Jul 31, 2011 at 10:16, Joel Abrahamsson
> > 
> > [m...@joelabrahamsson.com](mailto:m...@joelabrahamsson.com) wrote:
> > 
> > > Is it possible to somehow configure dynamic\_templates so that multiple  
> > > matching templates will be applied? It seems to me that only the first  
> > > matching template is used. I can see why that is, but if there's a  
> > > workaround I'd love to know about it 🙂
> > 
> > > As an example, I'm using something like the dynamic templates below  
> > > and would like strings to be mapped both as multifield and as not  
> > > included in all IF their names end with "!inall".
> > 
> > > {  
> > > "string\_template":{  
> > > "match":"_",  
> > > "match\_mapping\_type":"string",  
> > > "mapping":{  
> > > "type":"multi\_field",  
> > > "fields":{  
> > > "{name}":{  
> > > "type":"string",  
> > > "index":"not\_analyzed"  
> > > },  
> > > "standard":{  
> > > "type":"string"  
> > > }  
> > > }  
> > > }  
> > > }  
> > > },  
> > > {  
> > > "not\_in\_all\_template":{  
> > > "match":"_!inall",  
> > > "mapping":{  
> > > "include\_in\_all":false  
> > > }  
> > > }  
> > > },

---

<div class="post-metadata">

### Author: ![Joel\_Abrahamsson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joel_abrahamsson/32/1924_2.png) [@Joel\_Abrahamsson](https://discuss.elastic.co/u/Joel_Abrahamsson)
#### Post date: [July 31, 2011, 3:09pm UTC](https://discuss.elastic.co/t/several-matching-dynamic-templates/5007/6 "2011-07-31T15:09:08Z")

</div>

I see, thanks!

2011/7/31 Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com)

> There isn't support in dynamic templates to "aggregate templates", the  
> first one matches (ordered) will be used, so you need to provide full  
> mapping on relevant ones. Its a bit tricky (at least in the way its  
> implemented currently) to apply everything the matches to the new field  
> mapping introduced.
> 
> On Sun, Jul 31, 2011 at 6:00 PM, Joel Abrahamsson \<  
> [mail@joelabrahamsson.com](mailto:mail@joelabrahamsson.com)\> wrote:
> 
> > Oh, actually it seems we we're talking about different things. I'm not  
> > talking about index templates by dynamic templates for types/  
> > properties 🙂
> > 
> > On 31 Juli, 16:23, "Matthew A. Brown" [mat.a.br...@gmail.com](mailto:mat.a.br...@gmail.com) wrote:
> > 
> > > Hi Joel,
> > > 
> > > Multiple matching templates are supported by ES (see the end ofhttp://  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-templa)...).  
> > > It looks like you don't have a parallel structure between your two  
> > > mappings, though -- did you intend to put the 'include\_in\_all' key  
> > > inside a field definition?
> > > 
> > > Mat
> > > 
> > > On Sun, Jul 31, 2011 at 10:16, Joel Abrahamsson
> > > 
> > > [m...@joelabrahamsson.com](mailto:m...@joelabrahamsson.com) wrote:
> > > 
> > > > Is it possible to somehow configure dynamic\_templates so that multiple  
> > > > matching templates will be applied? It seems to me that only the first  
> > > > matching template is used. I can see why that is, but if there's a  
> > > > workaround I'd love to know about it 🙂
> > > 
> > > > As an example, I'm using something like the dynamic templates below  
> > > > and would like strings to be mapped both as multifield and as not  
> > > > included in all IF their names end with "!inall".
> > > 
> > > > {  
> > > > "string\_template":{  
> > > > "match":"_",  
> > > > "match\_mapping\_type":"string",  
> > > > "mapping":{  
> > > > "type":"multi\_field",  
> > > > "fields":{  
> > > > "{name}":{  
> > > > "type":"string",  
> > > > "index":"not\_analyzed"  
> > > > },  
> > > > "standard":{  
> > > > "type":"string"  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > },  
> > > > {  
> > > > "not\_in\_all\_template":{  
> > > > "match":"_!inall",  
> > > > "mapping":{  
> > > > "include\_in\_all":false  
> > > > }  
> > > > }  
> > > > },

---

<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: [July 6, 2017, 3:58am UTC](https://discuss.elastic.co/t/several-matching-dynamic-templates/5007/7 "2017-07-06T03:58:46Z")

</div>


