# Flexible index mappings

**URL:** <https://discuss.elastic.co/t/flexible-index-mappings/6651>\
**Category:** Elasticsearch\
**Created:** [February 9, 2012, 12:21am UTC](https://discuss.elastic.co/t/flexible-index-mappings/6651 "2012-02-09T00:21:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [February 9, 2012, 12:21am UTC](https://discuss.elastic.co/t/flexible-index-mappings/6651/1 "2012-02-09T00:21:50Z")

</div>

In my current setup, I am configuring new index mappings via a file on  
each node. File-based mappings allow me to change items at the  
application level and not via code, and are easier to manage in  
source-control.

However, with using index aliases, the only way I can apply to same  
mapping to each new index is by putting the file in the \_default  
directory. Currently the system is only using one index, so the  
solution is acceptable, but other indices will appear in the future.

Having a more flexible approach is needed, but I am unsure about any  
practical suggestions. Having wildcards in the directory name is ugly  
and not supported by Windows. Perhaps a default.json in the  
config/mappings directory with a slightly different JSON structure to  
allow index names (with wildcards)?

e.g.

{  
"myindex-\*" : {  
"mytype" : {  
"\_source" : {"enabled" : true},  
"\_all" : {"enabled" : true},  
"properties" : {  
...  
This file would have the lowest precedence in determining the correct mapping.

Or perhaps am I missing another solution altogether?

Cheers,

Ivan

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [February 9, 2012, 9:56am UTC](https://discuss.elastic.co/t/flexible-index-mappings/6651/2 "2012-02-09T09:56:01Z")

</div>

> Or perhaps am I missing another solution altogether?

In Elasticsearch you define per type

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Or did I misunderstand something?

Regards,  
Peter.

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [February 9, 2012, 4:03pm UTC](https://discuss.elastic.co/t/flexible-index-mappings/6651/3 "2012-02-09T16:03:40Z")

</div>

There are only two options for placing the mapping file: inside the  
\_default directory which applies to all indices, or inside a directory  
with the same name as an index. Types defined inside a mapping inside  
that \_default will apply to all indices, even if the type is not used.  
No performance issues, but the index metadata will have this mapping,  
which can be confusing.

On Thu, Feb 9, 2012 at 1:56 AM, Karussell [tableyourtime@googlemail.com](mailto:tableyourtime@googlemail.com) wrote:

> > Or perhaps am I missing another solution altogether?
> 
> In Elasticsearch you define per type
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> 
> Or did I misunderstand something?
> 
> Regards,  
> Peter.

---

<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 12, 2012, 11:20am UTC](https://discuss.elastic.co/t/flexible-index-mappings/6651/4 "2012-02-12T11:20:18Z")

</div>

How about using index templates? You can't place index templates in the configuration location of node(s), but you can place them when the system starts, and then they will apply to indices matching the relevant index name.

On Thursday, February 9, 2012 at 6:03 PM, Ivan Brusic wrote:

> There are only two options for placing the mapping file: inside the  
> \_default directory which applies to all indices, or inside a directory  
> with the same name as an index. Types defined inside a mapping inside  
> that \_default will apply to all indices, even if the type is not used.  
> No performance issues, but the index metadata will have this mapping,  
> which can be confusing.
> 
> On Thu, Feb 9, 2012 at 1:56 AM, Karussell \<[tableyourtime@googlemail.com](mailto:tableyourtime@googlemail.com) ([mailto:tableyourtime@googlemail.com](mailto:tableyourtime@googlemail.com))\> wrote:
> 
> > > Or perhaps am I missing another solution altogether?
> > 
> > In Elasticsearch you define per type
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> > 
> > Or did I misunderstand something?
> > 
> > Regards,  
> > Peter.

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [February 14, 2012, 10:56pm UTC](https://discuss.elastic.co/t/flexible-index-mappings/6651/5 "2012-02-14T22:56:58Z")

</div>

I did consider index templates since they allow the use of wildcards  
in the index name, but did not explore further since they are not file  
based.

Not sure what you mean by "you can place them when the system starts".  
Do you mean they can be added via the API at startup?

Ultimately, the file based approach might not work since they require a reboot.

--  
Ivan

On Sun, Feb 12, 2012 at 3:20 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> How about using index templates? You can't place index templates in the  
> configuration location of node(s), but you can place them when the system  
> starts, and then they will apply to indices matching the relevant index  
> name.
> 
> On Thursday, February 9, 2012 at 6:03 PM, Ivan Brusic wrote:
> 
> There are only two options for placing the mapping file: inside the  
> \_default directory which applies to all indices, or inside a directory  
> with the same name as an index. Types defined inside a mapping inside  
> that \_default will apply to all indices, even if the type is not used.  
> No performance issues, but the index metadata will have this mapping,  
> which can be confusing.
> 
> On Thu, Feb 9, 2012 at 1:56 AM, Karussell [tableyourtime@googlemail.com](mailto:tableyourtime@googlemail.com)  
> wrote:
> 
> Or perhaps am I missing another solution altogether?
> 
> In Elasticsearch you define per type
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> 
> Or did I misunderstand something?
> 
> Regards,  
> Peter.

---

<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 15, 2012, 10:36am UTC](https://discuss.elastic.co/t/flexible-index-mappings/6651/6 "2012-02-15T10:36:34Z")

</div>

I added this so you can place templates under config: [Index Templates: Allow to place them under config/templates · Issue #1703 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1703).

On Wednesday, February 15, 2012 at 12:56 AM, Ivan Brusic wrote:

> I did consider index templates since they allow the use of wildcards  
> in the index name, but did not explore further since they are not file  
> based.
> 
> Not sure what you mean by "you can place them when the system starts".  
> Do you mean they can be added via the API at startup?
> 
> Ultimately, the file based approach might not work since they require a reboot.
> 
> --  
> Ivan
> 
> On Sun, Feb 12, 2012 at 3:20 AM, Shay Banon \<[kimchy@gmail.com](mailto:kimchy@gmail.com) ([mailto:kimchy@gmail.com](mailto:kimchy@gmail.com))\> wrote:
> 
> > How about using index templates? You can't place index templates in the  
> > configuration location of node(s), but you can place them when the system  
> > starts, and then they will apply to indices matching the relevant index  
> > name.
> > 
> > On Thursday, February 9, 2012 at 6:03 PM, Ivan Brusic wrote:
> > 
> > There are only two options for placing the mapping file: inside the  
> > \_default directory which applies to all indices, or inside a directory  
> > with the same name as an index. Types defined inside a mapping inside  
> > that \_default will apply to all indices, even if the type is not used.  
> > No performance issues, but the index metadata will have this mapping,  
> > which can be confusing.
> > 
> > On Thu, Feb 9, 2012 at 1:56 AM, Karussell \<[tableyourtime@googlemail.com](mailto:tableyourtime@googlemail.com) ([mailto:tableyourtime@googlemail.com](mailto:tableyourtime@googlemail.com))\>  
> > wrote:
> > 
> > Or perhaps am I missing another solution altogether?
> > 
> > In Elasticsearch you define per type
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> > 
> > Or did I misunderstand something?
> > 
> > Regards,  
> > Peter.

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [March 14, 2012, 9:21pm UTC](https://discuss.elastic.co/t/flexible-index-mappings/6651/7 "2012-03-14T21:21:54Z")

</div>

Finally had a chance to test out the change with 0.19.0 (maintenance  
coding is taking up all my time). Works like a charm, but any  
modifications to a template are not reflected in the index, even after  
a restart. Is this an issue with dynamic templates (which I have never  
used) in general?

--  
Ivan

On Wed, Feb 15, 2012 at 2:36 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> I added this so you can place templates under  
> config: [Index Templates: Allow to place them under config/templates · Issue #1703 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1703).
> 
> On Wednesday, February 15, 2012 at 12:56 AM, Ivan Brusic wrote:
> 
> I did consider index templates since they allow the use of wildcards  
> in the index name, but did not explore further since they are not file  
> based.
> 
> Not sure what you mean by "you can place them when the system starts".  
> Do you mean they can be added via the API at startup?
> 
> Ultimately, the file based approach might not work since they require a  
> reboot.
> 
> --  
> Ivan
> 
> On Sun, Feb 12, 2012 at 3:20 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> How about using index templates? You can't place index templates in the  
> configuration location of node(s), but you can place them when the system  
> starts, and then they will apply to indices matching the relevant index  
> name.
> 
> On Thursday, February 9, 2012 at 6:03 PM, Ivan Brusic wrote:
> 
> There are only two options for placing the mapping file: inside the  
> \_default directory which applies to all indices, or inside a directory  
> with the same name as an index. Types defined inside a mapping inside  
> that \_default will apply to all indices, even if the type is not used.  
> No performance issues, but the index metadata will have this mapping,  
> which can be confusing.
> 
> On Thu, Feb 9, 2012 at 1:56 AM, Karussell [tableyourtime@googlemail.com](mailto:tableyourtime@googlemail.com)  
> wrote:
> 
> Or perhaps am I missing another solution altogether?
> 
> In Elasticsearch you define per type
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> 
> Or did I misunderstand something?
> 
> Regards,  
> Peter.

---

<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:** [March 15, 2012, 7:47am UTC](https://discuss.elastic.co/t/flexible-index-mappings/6651/8 "2012-03-15T07:47:48Z")

</div>

Hi Ivan,

I know it's a long shot, but are you sure you actually modified the  
template, and not entered a new one without deleting the old template?  
That's what I did yesterday, so I thought I should share 😃

To get all your templates, you can do something like this:

# curl -XGET '[http://localhost:9200/\_cluster/state?pretty=true](http://localhost:9200/_cluster/state?pretty=true)' \> /tmp/

cluster\_state\_dump

and then look in that file for "templates".

Best regards,  
Radu

On Mar 14, 11:21 pm, Ivan Brusic [i...@brusic.com](mailto:i...@brusic.com) wrote:

> Finally had a chance to test out the change with 0.19.0 (maintenance  
> coding is taking up all my time). Works like a charm, but any  
> modifications to a template are not reflected in the index, even after  
> a restart. Is this an issue with dynamic templates (which I have never  
> used) in general?
> 
> --  
> Ivan
> 
> On Wed, Feb 15, 2012 at 2:36 AM, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > I added this so you can place templates under  
> > config: [Index Templates: Allow to place them under config/templates · Issue #1703 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1703).
> 
> > On Wednesday, February 15, 2012 at 12:56 AM, Ivan Brusic wrote:
> 
> > I did consider index templates since they allow the use of wildcards  
> > in the index name, but did not explore further since they are not file  
> > based.
> 
> > Not sure what you mean by "you can place them when the system starts".  
> > Do you mean they can be added via the API at startup?
> 
> > Ultimately, the file based approach might not work since they require a  
> > reboot.
> 
> > --  
> > Ivan
> 
> > On Sun, Feb 12, 2012 at 3:20 AM, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > How about using index templates? You can't place index templates in the  
> > configuration location of node(s), but you can place them when the system  
> > starts, and then they will apply to indices matching the relevant index  
> > name.
> 
> > On Thursday, February 9, 2012 at 6:03 PM, Ivan Brusic wrote:
> 
> > There are only two options for placing the mapping file: inside the  
> > \_default directory which applies to all indices, or inside a directory  
> > with the same name as an index. Types defined inside a mapping inside  
> > that \_default will apply to all indices, even if the type is not used.  
> > No performance issues, but the index metadata will have this mapping,  
> > which can be confusing.
> 
> > On Thu, Feb 9, 2012 at 1:56 AM, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com)  
> > wrote:
> 
> > Or perhaps am I missing another solution altogether?
> 
> > In Elasticsearch you define per type
> 
> > [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> 
> > Or did I misunderstand something?
> 
> > Regards,  
> > Peter.

---

<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:** [March 16, 2012, 5:14pm UTC](https://discuss.elastic.co/t/flexible-index-mappings/6651/9 "2012-03-16T17:14:03Z")

</div>

Modifying the template will only apply to new indices created, not to  
existing indices...

On Wed, Mar 14, 2012 at 11:21 PM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> Finally had a chance to test out the change with 0.19.0 (maintenance  
> coding is taking up all my time). Works like a charm, but any  
> modifications to a template are not reflected in the index, even after  
> a restart. Is this an issue with dynamic templates (which I have never  
> used) in general?
> 
> --  
> Ivan
> 
> On Wed, Feb 15, 2012 at 2:36 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > I added this so you can place templates under  
> > config: [Index Templates: Allow to place them under config/templates · Issue #1703 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1703).
> > 
> > On Wednesday, February 15, 2012 at 12:56 AM, Ivan Brusic wrote:
> > 
> > I did consider index templates since they allow the use of wildcards  
> > in the index name, but did not explore further since they are not file  
> > based.
> > 
> > Not sure what you mean by "you can place them when the system starts".  
> > Do you mean they can be added via the API at startup?
> > 
> > Ultimately, the file based approach might not work since they require a  
> > reboot.
> > 
> > --  
> > Ivan
> > 
> > On Sun, Feb 12, 2012 at 3:20 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> > 
> > How about using index templates? You can't place index templates in the  
> > configuration location of node(s), but you can place them when the system  
> > starts, and then they will apply to indices matching the relevant index  
> > name.
> > 
> > On Thursday, February 9, 2012 at 6:03 PM, Ivan Brusic wrote:
> > 
> > There are only two options for placing the mapping file: inside the  
> > \_default directory which applies to all indices, or inside a directory  
> > with the same name as an index. Types defined inside a mapping inside  
> > that \_default will apply to all indices, even if the type is not used.  
> > No performance issues, but the index metadata will have this mapping,  
> > which can be confusing.
> > 
> > On Thu, Feb 9, 2012 at 1:56 AM, Karussell [tableyourtime@googlemail.com](mailto:tableyourtime@googlemail.com)  
> > wrote:
> > 
> > Or perhaps am I missing another solution altogether?
> > 
> > In Elasticsearch you define per type
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> > 
> > Or did I misunderstand something?
> > 
> > Regards,  
> > Peter.

---

<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:35am UTC](https://discuss.elastic.co/t/flexible-index-mappings/6651/10 "2017-07-06T03:35:52Z")

</div>


