# Dynamic Mapping

**URL:** <https://discuss.elastic.co/t/dynamic-mapping/6575>\
**Category:** Elasticsearch\
**Created:** [February 2, 2012, 6:19pm UTC](https://discuss.elastic.co/t/dynamic-mapping/6575 "2012-02-02T18:19:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sky\_Stebnicki1](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Sky\_Stebnicki1](https://discuss.elastic.co/u/Sky_Stebnicki1)\
**Post date:** [February 2, 2012, 6:19pm UTC](https://discuss.elastic.co/t/dynamic-mapping/6575/1 "2012-02-02T18:19:32Z")

</div>

Hi all, I'm new(er) to elasticsearch but pretty experienced with  
Apache Solr. In Solr there is a configuration option in solr that  
allows me to create dynamic mapping with the prefix or the postfix of  
a field name. For instance, if I index a field called 'myvalie\_i' then  
I can tell solr to always treat that field as an integer because of  
the "\*\_i" postfix.

Is there any way to do that in ElasticSearch?

Thanks so much!

Sky

---

<div class="post-metadata">

**Author:** ![Nick\_Hoffman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_hoffman/32/1872_2.png) [@Nick\_Hoffman](https://discuss.elastic.co/u/Nick_Hoffman)\
**Post date:** [February 2, 2012, 7:03pm UTC](https://discuss.elastic.co/t/dynamic-mapping/6575/2 "2012-02-02T19:03:18Z")

</div>

Hey there, Sky. Have a look at dynamic templates:  
[http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html](http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html)

---

<div class="post-metadata">

**Author:** ![Sky\_Stebnicki1](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Sky\_Stebnicki1](https://discuss.elastic.co/u/Sky_Stebnicki1)\
**Post date:** [February 7, 2012, 5:31am UTC](https://discuss.elastic.co/t/dynamic-mapping/6575/3 "2012-02-07T05:31:38Z")

</div>

Thanks for taking the time to write. That is definitely looking like  
what I will need. Do you know if there is any way to set the dynamic  
mapping template for an entire index rather than for each type?

So I would basically just create a new template for each type right?  
For example:

{  
"customer" :  
{  
"dynamic\_templates" : [  
{  
"template\_int" : {  
"match" : "_\_i",  
"mapping" : {  
"type" : "integer"  
}  
}  
},  
{  
"template\_str" : {  
"match" : "_\_s",  
"mapping" : {  
"type" : "string"  
}  
}  
}  
]  
}  
}

On Feb 2, 11:03 am, Nick Hoffman [n...@deadorange.com](mailto:n...@deadorange.com) wrote:

> Hey there, Sky. Have a look at dynamic templates:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)...

---

<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:** [February 7, 2012, 11:48am UTC](https://discuss.elastic.co/t/dynamic-mapping/6575/4 "2012-02-07T11:48:01Z")

</div>

When you put mapping against an index, you can specify the mapping type to be _default_, and it will apply to any mapping type in that index.

On Tuesday, February 7, 2012 at 7:31 AM, SkyStebnicki wrote:

> Thanks for taking the time to write. That is definitely looking like  
> what I will need. Do you know if there is any way to set the dynamic  
> mapping template for an entire index rather than for each type?
> 
> So I would basically just create a new template for each type right?  
> For example:
> 
> {  
> "customer" :  
> {  
> "dynamic\_templates" : [  
> {  
> "template\_int" : {  
> "match" : "_\_i",  
> "mapping" : {  
> "type" : "integer"  
> }  
> }  
> },  
> {  
> "template\_str" : {  
> "match" : "_\_s",  
> "mapping" : {  
> "type" : "string"  
> }  
> }  
> }  
> ]  
> }  
> }
> 
> On Feb 2, 11:03 am, Nick Hoffman \<[n...@deadorange.com](mailto:n...@deadorange.com) ([http://deadorange.com](http://deadorange.com))\> wrote:
> 
> > Hey there, Sky. Have a look at dynamic templates:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)...

---

<div class="post-metadata">

**Author:** ![Sky\_Stebnicki1](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Sky\_Stebnicki1](https://discuss.elastic.co/u/Sky_Stebnicki1)\
**Post date:** [February 8, 2012, 2:42am UTC](https://discuss.elastic.co/t/dynamic-mapping/6575/5 "2012-02-08T02:42:07Z")

</div>

Thanks Shay!

On Feb 7, 3:48 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> When you put mapping against an index, you can specify the mapping type to be _default_, and it will apply to any mapping type in that index.
> 
> On Tuesday, February 7, 2012 at 7:31 AM, SkyStebnicki wrote:
> 
> > Thanks for taking the time to write. That is definitely looking like  
> > what I will need. Do you know if there is any way to set the dynamic  
> > mapping template for an entire index rather than for each type?
> 
> > So I would basically just create a new template for each type right?  
> > For example:
> 
> > {  
> > "customer" :  
> > {  
> > "dynamic\_templates" : [  
> > {  
> > "template\_int" : {  
> > "match" : "_\_i",  
> > "mapping" : {  
> > "type" : "integer"  
> > }  
> > }  
> > },  
> > {  
> > "template\_str" : {  
> > "match" : "_\_s",  
> > "mapping" : {  
> > "type" : "string"  
> > }  
> > }  
> > }  
> > ]  
> > }  
> > }
> 
> > On Feb 2, 11:03 am, Nick Hoffman \<[n...@deadorange.com](mailto:n...@deadorange.com) ([http://deadorange.com](http://deadorange.com))\> wrote:
> > 
> > > Hey there, Sky. Have a look at dynamic templates:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)...

---

<div class="post-metadata">

**Author:** ![Sky\_Stebnicki1](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Sky\_Stebnicki1](https://discuss.elastic.co/u/Sky_Stebnicki1)\
**Post date:** [April 12, 2012, 2:39pm UTC](https://discuss.elastic.co/t/dynamic-mapping/6575/6 "2012-04-12T14:39:40Z")

</div>

Sorry to resurrect such an old thread, but I had one simple follow-up  
question. If I wanted to set this in a configuration file is that possible?  
For example:

/config/elasticsearch.yml

mappings :  
_default_ :  
dynamic\_templates :  
templ\_int :  
match : "\*\_i"  
mapping :  
type : "int"  
index : "not\_analyzed"  
store : "yes"

Thanks again for your help!

Sky

On Tuesday, February 7, 2012 3:48:01 AM UTC-8, kimchy wrote:

> When you put mapping against an index, you can specify the mapping type  
> to be _default_, and it will apply to any mapping type in that index.
> 
> On Tuesday, February 7, 2012 at 7:31 AM, SkyStebnicki wrote:
> 
> Thanks for taking the time to write. That is definitely looking like  
> what I will need. Do you know if there is any way to set the dynamic  
> mapping template for an entire index rather than for each type?
> 
> So I would basically just create a new template for each type right?  
> For example:
> 
> {  
> "customer" :  
> {  
> "dynamic\_templates" : [  
> {  
> "template\_int" : {  
> "match" : "_\_i",  
> "mapping" : {  
> "type" : "integer"  
> }  
> }  
> },  
> {  
> "template\_str" : {  
> "match" : "_\_s",  
> "mapping" : {  
> "type" : "string"  
> }  
> }  
> }  
> ]  
> }  
> }
> 
> On Feb 2, 11:03 am, Nick Hoffman [n...@deadorange.com](mailto:n...@deadorange.com) wrote:
> 
> Hey there, Sky. Have a look at dynamic templates:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)...

---

<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:** [April 13, 2012, 12:25pm UTC](https://discuss.elastic.co/t/dynamic-mapping/6575/7 "2012-04-13T12:25:02Z")

</div>

Not in elasticsearch.yml, but you can create an index template  
configuration, with a template matching \*. Btw, why do you need to have the  
int stored?

On Thu, Apr 12, 2012 at 5:39 PM, Sky Stebnicki [sky.stebnicki@gmail.com](mailto:sky.stebnicki@gmail.com)wrote:

> Sorry to resurrect such an old thread, but I had one simple follow-up  
> question. If I wanted to set this in a configuration file is that possible?  
> For example:
> 
> /config/elasticsearch.yml
> 
> mappings :  
> _default_ :  
> dynamic\_templates :  
> templ\_int :  
> match : "\*\_i"  
> mapping :  
> type : "int"  
> index : "not\_analyzed"  
> store : "yes"
> 
> Thanks again for your help!
> 
> Sky
> 
> On Tuesday, February 7, 2012 3:48:01 AM UTC-8, kimchy wrote:
> 
> > When you put mapping against an index, you can specify the mapping type  
> > to be _default_, and it will apply to any mapping type in that index.
> > 
> > On Tuesday, February 7, 2012 at 7:31 AM, SkyStebnicki wrote:
> > 
> > Thanks for taking the time to write. That is definitely looking like  
> > what I will need. Do you know if there is any way to set the dynamic  
> > mapping template for an entire index rather than for each type?
> > 
> > So I would basically just create a new template for each type right?  
> > For example:
> > 
> > {  
> > "customer" :  
> > {  
> > "dynamic\_templates" : [  
> > {  
> > "template\_int" : {  
> > "match" : "_\_i",  
> > "mapping" : {  
> > "type" : "integer"  
> > }  
> > }  
> > },  
> > {  
> > "template\_str" : {  
> > "match" : "_\_s",  
> > "mapping" : {  
> > "type" : "string"  
> > }  
> > }  
> > }  
> > ]  
> > }  
> > }
> > 
> > On Feb 2, 11:03 am, Nick Hoffman [n...@deadorange.com](mailto:n...@deadorange.com) wrote:
> > 
> > Hey there, Sky. Have a look at dynamic templates:[http://www](http://www).\*\*  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/ **reference/mapping/root-object-** type)[http://www.elasticsearch.org/guide/reference/mapping/root-object-type](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)  
> > ...

---

<div class="post-metadata">

**Author:** ![Sky\_Stebnicki1](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Sky\_Stebnicki1](https://discuss.elastic.co/u/Sky_Stebnicki1)\
**Post date:** [April 13, 2012, 2:35pm UTC](https://discuss.elastic.co/t/dynamic-mapping/6575/8 "2012-04-13T14:35:15Z")

</div>

Alright, that sounds like what I am looking for, but I cannot get it to  
work. I've tried and I'm missing something.

1. Create /config/templates/template1.yml

template : "_",  
mappings :  
 default :  
dynamic\_templates :  
templ\_int :  
match : "_\_i"  
mapping :  
type : "integer"  
index : "not\_analyzed"  
store : "yes"

I also tried  
template\_1 :  
template : "_",  
mappings :  
 default :  
dynamic\_templates :  
templ\_int :  
match : "_\_i"  
mapping :  
type : "integer"  
index : "not\_analyzed"  
store : "yes"

But neither of them are applying. [http://localhost:9200/\_all/\_mapping](http://localhost:9200/_all/_mapping)  
reveals:

{"test":{"customer":{"properties":{"owner\_id\_i":{"type":"date","format":"dateOptionalTime"}}}}}

After entering multiple items with fields that match \*\_i in the "test" index

And is there any reason I would not want to store int? I was just going off the mapping base types.

Thanks,

Sky

On Friday, April 13, 2012 5:25:02 AM UTC-7, kimchy wrote:

> Not in elasticsearch.yml, but you can create an index template  
> configuration, with a template matching \*. Btw, why do you need to have the  
> int stored?
> 
> On Thu, Apr 12, 2012 at 5:39 PM, Sky Stebnicki [sky.stebnicki@gmail.com](mailto:sky.stebnicki@gmail.com)wrote:
> 
> > Sorry to resurrect such an old thread, but I had one simple follow-up  
> > question. If I wanted to set this in a configuration file is that possible?  
> > For example:
> > 
> > /config/elasticsearch.yml
> > 
> > mappings :  
> > _default_ :  
> > dynamic\_templates :  
> > templ\_int :  
> > match : "\*\_i"  
> > mapping :  
> > type : "int"  
> > index : "not\_analyzed"  
> > store : "yes"
> > 
> > Thanks again for your help!
> > 
> > Sky
> > 
> > On Tuesday, February 7, 2012 3:48:01 AM UTC-8, kimchy wrote:
> > 
> > > When you put mapping against an index, you can specify the mapping type  
> > > to be _default_, and it will apply to any mapping type in that index.
> > > 
> > > On Tuesday, February 7, 2012 at 7:31 AM, SkyStebnicki wrote:
> > > 
> > > Thanks for taking the time to write. That is definitely looking like  
> > > what I will need. Do you know if there is any way to set the dynamic  
> > > mapping template for an entire index rather than for each type?
> > > 
> > > So I would basically just create a new template for each type right?  
> > > For example:
> > > 
> > > {  
> > > "customer" :  
> > > {  
> > > "dynamic\_templates" : [  
> > > {  
> > > "template\_int" : {  
> > > "match" : "_\_i",  
> > > "mapping" : {  
> > > "type" : "integer"  
> > > }  
> > > }  
> > > },  
> > > {  
> > > "template\_str" : {  
> > > "match" : "_\_s",  
> > > "mapping" : {  
> > > "type" : "string"  
> > > }  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > }
> > > 
> > > On Feb 2, 11:03 am, Nick Hoffman [n...@deadorange.com](mailto:n...@deadorange.com) wrote:
> > > 
> > > Hey there, Sky. Have a look at dynamic templates:[http://www](http://www).\*\*  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/ **reference/mapping/root-object-** type)[http://www.elasticsearch.org/guide/reference/mapping/root-object-type](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)  
> > > ...

On Friday, April 13, 2012 5:25:02 AM UTC-7, kimchy wrote:

> Not in elasticsearch.yml, but you can create an index template  
> configuration, with a template matching \*. Btw, why do you need to have the  
> int stored?
> 
> On Thu, Apr 12, 2012 at 5:39 PM, Sky Stebnicki [sky.stebnicki@gmail.com](mailto:sky.stebnicki@gmail.com)wrote:
> 
> > Sorry to resurrect such an old thread, but I had one simple follow-up  
> > question. If I wanted to set this in a configuration file is that possible?  
> > For example:
> > 
> > /config/elasticsearch.yml
> > 
> > mappings :  
> > _default_ :  
> > dynamic\_templates :  
> > templ\_int :  
> > match : "\*\_i"  
> > mapping :  
> > type : "int"  
> > index : "not\_analyzed"  
> > store : "yes"
> > 
> > Thanks again for your help!
> > 
> > Sky
> > 
> > On Tuesday, February 7, 2012 3:48:01 AM UTC-8, kimchy wrote:
> > 
> > > When you put mapping against an index, you can specify the mapping type  
> > > to be _default_, and it will apply to any mapping type in that index.
> > > 
> > > On Tuesday, February 7, 2012 at 7:31 AM, SkyStebnicki wrote:
> > > 
> > > Thanks for taking the time to write. That is definitely looking like  
> > > what I will need. Do you know if there is any way to set the dynamic  
> > > mapping template for an entire index rather than for each type?
> > > 
> > > So I would basically just create a new template for each type right?  
> > > For example:
> > > 
> > > {  
> > > "customer" :  
> > > {  
> > > "dynamic\_templates" : [  
> > > {  
> > > "template\_int" : {  
> > > "match" : "_\_i",  
> > > "mapping" : {  
> > > "type" : "integer"  
> > > }  
> > > }  
> > > },  
> > > {  
> > > "template\_str" : {  
> > > "match" : "_\_s",  
> > > "mapping" : {  
> > > "type" : "string"  
> > > }  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > }
> > > 
> > > On Feb 2, 11:03 am, Nick Hoffman [n...@deadorange.com](mailto:n...@deadorange.com) wrote:
> > > 
> > > Hey there, Sky. Have a look at dynamic templates:[http://www](http://www).\*\*  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/ **reference/mapping/root-object-** type)[http://www.elasticsearch.org/guide/reference/mapping/root-object-type](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)  
> > > ...

On Friday, April 13, 2012 5:25:02 AM UTC-7, kimchy wrote:

> Not in elasticsearch.yml, but you can create an index template  
> configuration, with a template matching \*. Btw, why do you need to have the  
> int stored?
> 
> On Thu, Apr 12, 2012 at 5:39 PM, Sky Stebnicki [sky.stebnicki@gmail.com](mailto:sky.stebnicki@gmail.com)wrote:
> 
> > Sorry to resurrect such an old thread, but I had one simple follow-up  
> > question. If I wanted to set this in a configuration file is that possible?  
> > For example:
> > 
> > /config/elasticsearch.yml
> > 
> > mappings :  
> > _default_ :  
> > dynamic\_templates :  
> > templ\_int :  
> > match : "\*\_i"  
> > mapping :  
> > type : "int"  
> > index : "not\_analyzed"  
> > store : "yes"
> > 
> > Thanks again for your help!
> > 
> > Sky
> > 
> > On Tuesday, February 7, 2012 3:48:01 AM UTC-8, kimchy wrote:
> > 
> > > When you put mapping against an index, you can specify the mapping type  
> > > to be _default_, and it will apply to any mapping type in that index.
> > > 
> > > On Tuesday, February 7, 2012 at 7:31 AM, SkyStebnicki wrote:
> > > 
> > > Thanks for taking the time to write. That is definitely looking like  
> > > what I will need. Do you know if there is any way to set the dynamic  
> > > mapping template for an entire index rather than for each type?
> > > 
> > > So I would basically just create a new template for each type right?  
> > > For example:
> > > 
> > > {  
> > > "customer" :  
> > > {  
> > > "dynamic\_templates" : [  
> > > {  
> > > "template\_int" : {  
> > > "match" : "_\_i",  
> > > "mapping" : {  
> > > "type" : "integer"  
> > > }  
> > > }  
> > > },  
> > > {  
> > > "template\_str" : {  
> > > "match" : "_\_s",  
> > > "mapping" : {  
> > > "type" : "string"  
> > > }  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > }
> > > 
> > > On Feb 2, 11:03 am, Nick Hoffman [n...@deadorange.com](mailto:n...@deadorange.com) wrote:
> > > 
> > > Hey there, Sky. Have a look at dynamic templates:[http://www](http://www).\*\*  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/ **reference/mapping/root-object-** type)[http://www.elasticsearch.org/guide/reference/mapping/root-object-type](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)  
> > > ...

---

<div class="post-metadata">

**Author:** ![Radu\_Gheorghe1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe1/32/2688_2.png) [@Radu\_Gheorghe1](https://discuss.elastic.co/u/Radu_Gheorghe1)\
**Post date:** [April 14, 2012, 4:58pm UTC](https://discuss.elastic.co/t/dynamic-mapping/6575/9 "2012-04-14T16:58:26Z")

</div>

AFAIK, if you put templates there, they should be in JSON, not YML:

> <https://github.com/elastic/elasticsearch/issues/1703>
>
> Allow to place index templates under the \`config\` location within the \`templates…\` directory. For example, a file called \`config/templates/tempalte\_1.json\` can be placed and it will be applied when it matches an index creation. A sample content for the mentioned file can be: 
> 
> \`\`\`
> {
> "template\_1" : {
> "template" : "\*",
> "settings" : {
> "index.number\_of\_shards" : 2
> },
> "mappings" : {
> "\_default\_" : {
> "\_source" : {
> "enabled" : false
> }
> },
> "type1" : {
> "\_all" : {
> "enabled" : false
> }
> }
> }
> }
> }
> \`\`\`

Please note that the template is added when it matches an index. So I  
couldn't see my configured template when I checked the cluster state,  
as opposed to how I see them when I just put them via HTTP.

On Apr 13, 4:35 pm, Sky Stebnicki [sky.stebni...@gmail.com](mailto:sky.stebni...@gmail.com) wrote:

> Alright, that sounds like what I am looking for, but I cannot get it to  
> work. I've tried and I'm missing something.
> 
> 1. Create /config/templates/template1.yml
> 
> template : "_",  
> mappings :  
> default :  
> dynamic\_templates :  
> templ\_int :  
> match : "_\_i"  
> mapping :  
> type : "integer"  
> index : "not\_analyzed"  
> store : "yes"
> 
> I also tried  
> template\_1 :  
> template : "_",  
> mappings :  
> default :  
> dynamic\_templates :  
> templ\_int :  
> match : "_\_i"  
> mapping :  
> type : "integer"  
> index : "not\_analyzed"  
> store : "yes"
> 
> But neither of them are applying.[http://localhost:9200/\_all/\_mapping](http://localhost:9200/_all/_mapping)  
> reveals:
> 
> {"test":{"customer":{"properties":{"owner\_id\_i":{"type":"date","format":"dateOptionalTime"}}}}}
> 
> After entering multiple items with fields that match \*\_i in the "test" index
> 
> And is there any reason I would not want to store int? I was just going off the mapping base types.
> 
> Thanks,
> 
> Sky
> 
> On Friday, April 13, 2012 5:25:02 AM UTC-7, kimchy wrote:
> 
> > Not in elasticsearch.yml, but you can create an index template  
> > configuration, with a template matching \*. Btw, why do you need to have the  
> > int stored?
> 
> > On Thu, Apr 12, 2012 at 5:39 PM, Sky Stebnicki [sky.stebni...@gmail.com](mailto:sky.stebni...@gmail.com)wrote:
> 
> > > Sorry to resurrect such an old thread, but I had one simple follow-up  
> > > question. If I wanted to set this in a configuration file is that possible?  
> > > For example:
> 
> > > /config/elasticsearch.yml
> 
> > > mappings :  
> > > _default_ :  
> > > dynamic\_templates :  
> > > templ\_int :  
> > > match : "\*\_i"  
> > > mapping :  
> > > type : "int"  
> > > index : "not\_analyzed"  
> > > store : "yes"
> 
> > > Thanks again for your help!
> 
> > > Sky
> 
> > > On Tuesday, February 7, 2012 3:48:01 AM UTC-8, kimchy wrote:
> 
> > > > When you put mapping against an index, you can specify the mapping type  
> > > > to be _default_, and it will apply to any mapping type in that index.
> 
> > > > On Tuesday, February 7, 2012 at 7:31 AM, SkyStebnicki wrote:
> 
> > > > Thanks for taking the time to write. That is definitely looking like  
> > > > what I will need. Do you know if there is any way to set the dynamic  
> > > > mapping template for an entire index rather than for each type?
> 
> > > > So I would basically just create a new template for each type right?  
> > > > For example:
> 
> > > > {  
> > > > "customer" :  
> > > > {  
> > > > "dynamic\_templates" : [  
> > > > {  
> > > > "template\_int" : {  
> > > > "match" : "_\_i",  
> > > > "mapping" : {  
> > > > "type" : "integer"  
> > > > }  
> > > > }  
> > > > },  
> > > > {  
> > > > "template\_str" : {  
> > > > "match" : "_\_s",  
> > > > "mapping" : {  
> > > > "type" : "string"  
> > > > }  
> > > > }  
> > > > }  
> > > > ]  
> > > > }  
> > > > }
> 
> > > > On Feb 2, 11:03 am, Nick Hoffman [n...@deadorange.com](mailto:n...@deadorange.com) wrote:
> 
> > > > Hey there, Sky. Have a look at dynamic templates:[http://www](http://www).\*\*  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/ **reference/mapping/root-object-** type)[http://www.elasticsearch.org/guide/reference/mapping/root-object-type](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)  
> > > > ...
> 
> On Friday, April 13, 2012 5:25:02 AM UTC-7, kimchy wrote:
> 
> > Not in elasticsearch.yml, but you can create an index template  
> > configuration, with a template matching \*. Btw, why do you need to have the  
> > int stored?
> 
> > On Thu, Apr 12, 2012 at 5:39 PM, Sky Stebnicki [sky.stebni...@gmail.com](mailto:sky.stebni...@gmail.com)wrote:
> 
> > > Sorry to resurrect such an old thread, but I had one simple follow-up  
> > > question. If I wanted to set this in a configuration file is that possible?  
> > > For example:
> 
> > > /config/elasticsearch.yml
> 
> > > mappings :  
> > > _default_ :  
> > > dynamic\_templates :  
> > > templ\_int :  
> > > match : "\*\_i"  
> > > mapping :  
> > > type : "int"  
> > > index : "not\_analyzed"  
> > > store : "yes"
> 
> > > Thanks again for your help!
> 
> > > Sky
> 
> > > On Tuesday, February 7, 2012 3:48:01 AM UTC-8, kimchy wrote:
> 
> > > > When you put mapping against an index, you can specify the mapping type  
> > > > to be _default_, and it will apply to any mapping type in that index.
> 
> > > > On Tuesday, February 7, 2012 at 7:31 AM, SkyStebnicki wrote:
> 
> > > > Thanks for taking the time to write. That is definitely looking like  
> > > > what I will need. Do you know if there is any way to set the dynamic  
> > > > mapping template for an entire index rather than for each type?
> 
> > > > So I would basically just create a new template for each type right?  
> > > > For example:
> 
> > > > {  
> > > > "customer" :  
> > > > {  
> > > > "dynamic\_templates" : [  
> > > > {  
> > > > "template\_int" : {  
> > > > "match" : "_\_i",  
> > > > "mapping" : {  
> > > > "type" : "integer"  
> > > > }  
> > > > }  
> > > > },  
> > > > {  
> > > > "template\_str" : {  
> > > > "match" : "_\_s",  
> > > > "mapping" : {  
> > > > "type" : "string"  
> > > > }  
> > > > }  
> > > > }  
> > > > ]  
> > > > }  
> > > > }
> 
> > > > On Feb 2, 11:03 am, Nick Hoffman [n...@deadorange.com](mailto:n...@deadorange.com) wrote:
> 
> > > > Hey there, Sky. Have a look at dynamic templates:[http://www](http://www).\*\*  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/ **reference/mapping/root-object-** type)[http://www.elasticsearch.org/guide/reference/mapping/root-object-type](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)  
> > > > ...
> 
> On Friday, April 13, 2012 5:25:02 AM UTC-7, kimchy wrote:
> 
> > Not in elasticsearch.yml, but you can create an index template  
> > configuration, with a template matching \*. Btw, why do you need to have the  
> > int stored?
> 
> > On Thu, Apr 12, 2012 at 5:39 PM, Sky Stebnicki [sky.stebni...@gmail.com](mailto:sky.stebni...@gmail.com)wrote:
> 
> > > Sorry to resurrect such an old thread, but I had one simple follow-up  
> > > question. If I wanted to set this in a configuration file is that possible?  
> > > For example:
> 
> > > /config/elasticsearch.yml
> 
> > > mappings :  
> > > _default_ :  
> > > dynamic\_templates :  
> > > templ\_int :  
> > > match : "\*\_i"  
> > > mapping :  
> > > type : "int"  
> > > index : "not\_analyzed"  
> > > store : "yes"
> 
> > > Thanks again for your help!
> 
> > > Sky
> 
> > > On Tuesday, February 7, 2012 3:48:01 AM UTC-8, kimchy wrote:
> 
> > > > When you put mapping against an index, you can specify the mapping type  
> > > > to be _default_, and it will apply to any mapping type in that index.
> 
> > > > On Tuesday, February 7, 2012 at 7:31 AM, SkyStebnicki wrote:
> 
> > > > Thanks for taking the time to write. That is definitely looking like  
> > > > what I will need. Do you know if there is any way to set the dynamic  
> > > > mapping template for an entire index rather than for each type?
> 
> > > > So I would basically just create a new template for each type right?  
> > > > For example:
> 
> > > > {  
> > > > "customer" :  
> > > > {  
> > > > "dynamic\_templates" : [  
> > > > {  
> > > > "template\_int" : {  
> > > > "match" : "_\_i",  
> > > > "mapping" : {  
> > > > "type" : "integer"  
> > > > }  
> > > > }  
> > > > },  
> > > > {  
> > > > "template\_str" : {  
> > > > "match" : "_\_s",  
> > > > "mapping" : {  
> > > > "type" : "string"  
> > > > }  
> > > > }  
> > > > }  
> > > > ]  
> > > > }  
> > > > }
> 
> > > > On Feb 2, 11:03 am, Nick Hoffman [n...@deadorange.com](mailto:n...@deadorange.com) wrote:
> 
> > > > Hey there, Sky. Have a look at dynamic templates:[http://www](http://www).\*\*  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/ **reference/mapping/root-object-** type)[http://www.elasticsearch.org/guide/reference/mapping/root-object-type](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)  
> > > > ...

---

<div class="post-metadata">

**Author:** ![Sky\_Stebnicki1](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@Sky\_Stebnicki1](https://discuss.elastic.co/u/Sky_Stebnicki1)\
**Post date:** [April 16, 2012, 2:51pm UTC](https://discuss.elastic.co/t/dynamic-mapping/6575/10 "2012-04-16T14:51:39Z")

</div>

Hmm, the json document is not being applied either. However, I have decided  
to just create the template though the API every time the index is created  
and that appears to be working really well. Thanks for all your help, the  
dynamic templates are exactly what I needed!

On Saturday, April 14, 2012 9:58:26 AM UTC-7, Radu Gheorghe wrote:

> AFAIK, if you put templates there, they should be in JSON, not YML:  
> [Index Templates: Allow to place them under config/templates · Issue #1703 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1703)
> 
> Please note that the template is added when it matches an index. So I  
> couldn't see my configured template when I checked the cluster state,  
> as opposed to how I see them when I just put them via HTTP.
> 
> On Apr 13, 4:35 pm, Sky Stebnicki [sky.stebni...@gmail.com](mailto:sky.stebni...@gmail.com) wrote:
> 
> > Alright, that sounds like what I am looking for, but I cannot get it to  
> > work. I've tried and I'm missing something.
> > 
> > 1. Create /config/templates/template1.yml
> > 
> > template : "_",  
> > mappings :  
> > default :  
> > dynamic\_templates :  
> > templ\_int :  
> > match : "_\_i"  
> > mapping :  
> > type : "integer"  
> > index : "not\_analyzed"  
> > store : "yes"
> > 
> > I also tried  
> > template\_1 :  
> > template : "_",  
> > mappings :  
> > default :  
> > dynamic\_templates :  
> > templ\_int :  
> > match : "_\_i"  
> > mapping :  
> > type : "integer"  
> > index : "not\_analyzed"  
> > store : "yes"
> > 
> > But neither of them are applying.[http://localhost:9200/\_all/\_mapping](http://localhost:9200/_all/_mapping)  
> > reveals:
> 
> {"test":{"customer":{"properties":{"owner\_id\_i":{"type":"date","format":"dateOptionalTime"}}}}}
> 
> > After entering multiple items with fields that match \*\_i in the "test"  
> > index
> > 
> > And is there any reason I would not want to store int? I was just going  
> > off the mapping base types.
> > 
> > Thanks,
> > 
> > Sky
> > 
> > On Friday, April 13, 2012 5:25:02 AM UTC-7, kimchy wrote:
> > 
> > > Not in elasticsearch.yml, but you can create an index template  
> > > configuration, with a template matching \*. Btw, why do you need to  
> > > have the  
> > > int stored?
> > 
> > > On Thu, Apr 12, 2012 at 5:39 PM, Sky Stebnicki \<  
> > > [sky.stebni...@gmail.com](mailto:sky.stebni...@gmail.com)\>wrote:
> > 
> > > > Sorry to resurrect such an old thread, but I had one simple follow-up  
> > > > question. If I wanted to set this in a configuration file is that  
> > > > possible?  
> > > > For example:
> > 
> > > > /config/elasticsearch.yml
> > 
> > > > mappings :  
> > > > _default_ :  
> > > > dynamic\_templates :  
> > > > templ\_int :  
> > > > match : "\*\_i"  
> > > > mapping :  
> > > > type : "int"  
> > > > index : "not\_analyzed"  
> > > > store : "yes"
> > 
> > > > Thanks again for your help!
> > 
> > > > Sky
> > 
> > > > On Tuesday, February 7, 2012 3:48:01 AM UTC-8, kimchy wrote:
> > 
> > > > > When you put mapping against an index, you can specify the mapping  
> > > > > type  
> > > > > to be _default_, and it will apply to any mapping type in that  
> > > > > index.
> > 
> > > > > On Tuesday, February 7, 2012 at 7:31 AM, SkyStebnicki wrote:
> > 
> > > > > Thanks for taking the time to write. That is definitely looking like  
> > > > > what I will need. Do you know if there is any way to set the dynamic  
> > > > > mapping template for an entire index rather than for each type?
> > 
> > > > > So I would basically just create a new template for each type right?  
> > > > > For example:
> > 
> > > > > {  
> > > > > "customer" :  
> > > > > {  
> > > > > "dynamic\_templates" : [  
> > > > > {  
> > > > > "template\_int" : {  
> > > > > "match" : "_\_i",  
> > > > > "mapping" : {  
> > > > > "type" : "integer"  
> > > > > }  
> > > > > }  
> > > > > },  
> > > > > {  
> > > > > "template\_str" : {  
> > > > > "match" : "_\_s",  
> > > > > "mapping" : {  
> > > > > "type" : "string"  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > ]  
> > > > > }  
> > > > > }
> > 
> > > > > On Feb 2, 11:03 am, Nick Hoffman [n...@deadorange.com](mailto:n...@deadorange.com) wrote:
> > 
> > > > > Hey there, Sky. Have a look at dynamic templates:[http://www](http://www).\*\*  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/ **reference/mapping/root-object-** type)\<  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)\>  
> > > > > ...
> > 
> > On Friday, April 13, 2012 5:25:02 AM UTC-7, kimchy wrote:
> > 
> > > Not in elasticsearch.yml, but you can create an index template  
> > > configuration, with a template matching \*. Btw, why do you need to  
> > > have the  
> > > int stored?
> > 
> > > On Thu, Apr 12, 2012 at 5:39 PM, Sky Stebnicki \<  
> > > [sky.stebni...@gmail.com](mailto:sky.stebni...@gmail.com)\>wrote:
> > 
> > > > Sorry to resurrect such an old thread, but I had one simple follow-up  
> > > > question. If I wanted to set this in a configuration file is that  
> > > > possible?  
> > > > For example:
> > 
> > > > /config/elasticsearch.yml
> > 
> > > > mappings :  
> > > > _default_ :  
> > > > dynamic\_templates :  
> > > > templ\_int :  
> > > > match : "\*\_i"  
> > > > mapping :  
> > > > type : "int"  
> > > > index : "not\_analyzed"  
> > > > store : "yes"
> > 
> > > > Thanks again for your help!
> > 
> > > > Sky
> > 
> > > > On Tuesday, February 7, 2012 3:48:01 AM UTC-8, kimchy wrote:
> > 
> > > > > When you put mapping against an index, you can specify the mapping  
> > > > > type  
> > > > > to be _default_, and it will apply to any mapping type in that  
> > > > > index.
> > 
> > > > > On Tuesday, February 7, 2012 at 7:31 AM, SkyStebnicki wrote:
> > 
> > > > > Thanks for taking the time to write. That is definitely looking like  
> > > > > what I will need. Do you know if there is any way to set the dynamic  
> > > > > mapping template for an entire index rather than for each type?
> > 
> > > > > So I would basically just create a new template for each type right?  
> > > > > For example:
> > 
> > > > > {  
> > > > > "customer" :  
> > > > > {  
> > > > > "dynamic\_templates" : [  
> > > > > {  
> > > > > "template\_int" : {  
> > > > > "match" : "_\_i",  
> > > > > "mapping" : {  
> > > > > "type" : "integer"  
> > > > > }  
> > > > > }  
> > > > > },  
> > > > > {  
> > > > > "template\_str" : {  
> > > > > "match" : "_\_s",  
> > > > > "mapping" : {  
> > > > > "type" : "string"  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > ]  
> > > > > }  
> > > > > }
> > 
> > > > > On Feb 2, 11:03 am, Nick Hoffman [n...@deadorange.com](mailto:n...@deadorange.com) wrote:
> > 
> > > > > Hey there, Sky. Have a look at dynamic templates:[http://www](http://www).\*\*  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/ **reference/mapping/root-object-** type)\<  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)\>  
> > > > > ...
> > 
> > On Friday, April 13, 2012 5:25:02 AM UTC-7, kimchy wrote:
> > 
> > > Not in elasticsearch.yml, but you can create an index template  
> > > configuration, with a template matching \*. Btw, why do you need to  
> > > have the  
> > > int stored?
> > 
> > > On Thu, Apr 12, 2012 at 5:39 PM, Sky Stebnicki \<  
> > > [sky.stebni...@gmail.com](mailto:sky.stebni...@gmail.com)\>wrote:
> > 
> > > > Sorry to resurrect such an old thread, but I had one simple follow-up  
> > > > question. If I wanted to set this in a configuration file is that  
> > > > possible?  
> > > > For example:
> > 
> > > > /config/elasticsearch.yml
> > 
> > > > mappings :  
> > > > _default_ :  
> > > > dynamic\_templates :  
> > > > templ\_int :  
> > > > match : "\*\_i"  
> > > > mapping :  
> > > > type : "int"  
> > > > index : "not\_analyzed"  
> > > > store : "yes"
> > 
> > > > Thanks again for your help!
> > 
> > > > Sky
> > 
> > > > On Tuesday, February 7, 2012 3:48:01 AM UTC-8, kimchy wrote:
> > 
> > > > > When you put mapping against an index, you can specify the mapping  
> > > > > type  
> > > > > to be _default_, and it will apply to any mapping type in that  
> > > > > index.
> > 
> > > > > On Tuesday, February 7, 2012 at 7:31 AM, SkyStebnicki wrote:
> > 
> > > > > Thanks for taking the time to write. That is definitely looking like  
> > > > > what I will need. Do you know if there is any way to set the dynamic  
> > > > > mapping template for an entire index rather than for each type?
> > 
> > > > > So I would basically just create a new template for each type right?  
> > > > > For example:
> > 
> > > > > {  
> > > > > "customer" :  
> > > > > {  
> > > > > "dynamic\_templates" : [  
> > > > > {  
> > > > > "template\_int" : {  
> > > > > "match" : "_\_i",  
> > > > > "mapping" : {  
> > > > > "type" : "integer"  
> > > > > }  
> > > > > }  
> > > > > },  
> > > > > {  
> > > > > "template\_str" : {  
> > > > > "match" : "_\_s",  
> > > > > "mapping" : {  
> > > > > "type" : "string"  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > ]  
> > > > > }  
> > > > > }
> > 
> > > > > On Feb 2, 11:03 am, Nick Hoffman [n...@deadorange.com](mailto:n...@deadorange.com) wrote:
> > 
> > > > > Hey there, Sky. Have a look at dynamic templates:[http://www](http://www).\*\*  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/ **reference/mapping/root-object-** type)\<  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)\>  
> > > > > ...

---

<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:32am UTC](https://discuss.elastic.co/t/dynamic-mapping/6575/11 "2017-07-06T03:32:26Z")

</div>


