# Disabling dynamic mapping

**URL:** https://discuss.elastic.co/t/disabling-dynamic-mapping/10659
**Category:** Elasticsearch
**Created:** [February 7, 2013, 10:17pm UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping/10659 "2013-02-07T22:17:30Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![T\_Vinod\_Gupta](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@T\_Vinod\_Gupta](https://discuss.elastic.co/u/T_Vinod_Gupta)
#### Post date: [February 7, 2013, 10:17pm UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping/10659/1 "2013-02-07T22:17:30Z")

</div>

i wanted to disable dynamic mapping for my indices.. but it is somehow not  
working for me.. i looked at the documentation and im still getting  
confused.. tried couple of things and it didnt work.

does anyone have a working example?

e.g., i tried the below and that didnt work -  
{ "number\_of\_shards" : 2,  
"mapper.dynamic" : false  
}

i looked at this link -  
[http://www.elasticsearch.org/guide/reference/mapping/object-type.html](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)

it doesnt really tell how to disable at root level.

thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)
#### Post date: [February 8, 2013, 7:09am UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping/10659/2 "2013-02-08T07:09:35Z")

</div>

Hello,

Here's a gist that you can adapt for a specific index:

> <https://gist.github.com/radu-gheorghe/4737210>

If you need to do this globally, you can add this line to your  
elasticsearch.yml:  
index.mapper.dynamic: false

Restart Elasticsearch, and it should work for all new indices.  
Alternatively, you should be able to do it with a template that matches all  
indices, or the index names your interested in.

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Fri, Feb 8, 2013 at 12:17 AM, T Vinod Gupta [tvinod@readypulse.com](mailto:tvinod@readypulse.com)wrote:

> i wanted to disable dynamic mapping for my indices.. but it is somehow not  
> working for me.. i looked at the documentation and im still getting  
> confused.. tried couple of things and it didnt work.
> 
> does anyone have a working example?
> 
> e.g., i tried the below and that didnt work -  
> { "number\_of\_shards" : 2,  
> "mapper.dynamic" : false  
> }
> 
> i looked at this link -  
> [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> 
> it doesnt really tell how to disable at root level.
> 
> thanks
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Michael\_Kleen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_kleen/32/2496_2.png) [@Michael\_Kleen](https://discuss.elastic.co/u/Michael_Kleen)
#### Post date: [February 8, 2013, 10:15am UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping/10659/3 "2013-02-08T10:15:14Z")

</div>

Hello,

if you want to disable the dynamic mapping on the root level of your object  
as you asked for and not on the complete index as Radu mentioned you can do  
it in the following way:

[https://gist.github.com/mkleen/4942355b8af22daa4a4e](https://gist.github.com/mkleen/4942355b8af22daa4a4e)

This will not prevent that an object gets created with unmapped fields, but  
it wont create a dynamic field in the index as shown above in the example.

Regards,

Michael

On Thursday, February 7, 2013 11:17:30 PM UTC+1, T Vinod Gupta wrote:

> i wanted to disable dynamic mapping for my indices.. but it is somehow not  
> working for me.. i looked at the documentation and im still getting  
> confused.. tried couple of things and it didnt work.
> 
> does anyone have a working example?
> 
> e.g., i tried the below and that didnt work -  
> { "number\_of\_shards" : 2,  
> "mapper.dynamic" : false  
> }
> 
> i looked at this link -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> 
> it doesnt really tell how to disable at root level.
> 
> thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![T\_Vinod\_Gupta](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@T\_Vinod\_Gupta](https://discuss.elastic.co/u/T_Vinod_Gupta)
#### Post date: [February 8, 2013, 11:15pm UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping/10659/4 "2013-02-08T23:15:48Z")

</div>

thanks a lot!

On Fri, Feb 8, 2013 at 2:15 AM, Michael Kleen  
[michael.kleen@numberfour.eu](mailto:michael.kleen@numberfour.eu)wrote:

> Hello,
> 
> if you want to disable the dynamic mapping on the root level of your  
> object as you asked for and not on the complete index as Radu mentioned  
> you can do it in the following way:
> 
> [https://gist.github.com/mkleen/4942355b8af22daa4a4e](https://gist.github.com/mkleen/4942355b8af22daa4a4e)
> 
> This will not prevent that an object gets created with unmapped fields,  
> but it wont create a dynamic field in the index as shown above in the  
> example.
> 
> Regards,
> 
> Michael
> 
> On Thursday, February 7, 2013 11:17:30 PM UTC+1, T Vinod Gupta wrote:
> 
> > i wanted to disable dynamic mapping for my indices.. but it is somehow  
> > not working for me.. i looked at the documentation and im still getting  
> > confused.. tried couple of things and it didnt work.
> > 
> > does anyone have a working example?
> > 
> > e.g., i tried the below and that didnt work -  
> > { "number\_of\_shards" : 2,  
> > "mapper.dynamic" : false  
> > }
> > 
> > i looked at this link - [http://www.elasticsearch](http://www.elasticsearch).\*\*  
> > org/guide/reference/mapping/\*\*object-type.html[http://www.elasticsearch.org/guide/reference/mapping/object-type.html](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> > 
> > it doesnt really tell how to disable at root level.
> > 
> > thanks
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Christopher\_J\_Bottar](https://avatars.discourse-cdn.com/v4/letter/c/e0b2c6/32.png) [@Christopher\_J\_Bottar](https://discuss.elastic.co/u/Christopher_J_Bottar)
#### Post date: [February 20, 2013, 5:25pm UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping/10659/5 "2013-02-20T17:25:47Z")

</div>

How about if I want an error raised if I try to index a field that's not  
defined as a part of the mapping?

Thanks.

On Friday, February 8, 2013 4:15:14 AM UTC-6, Michael Kleen wrote:

> Hello,
> 
> if you want to disable the dynamic mapping on the root level of your  
> object as you asked for and not on the complete index as Radu mentioned  
> you can do it in the following way:
> 
> [https://gist.github.com/mkleen/4942355b8af22daa4a4e](https://gist.github.com/mkleen/4942355b8af22daa4a4e)
> 
> This will not prevent that an object gets created with unmapped fields,  
> but it wont create a dynamic field in the index as shown above in the  
> example.
> 
> Regards,
> 
> Michael
> 
> On Thursday, February 7, 2013 11:17:30 PM UTC+1, T Vinod Gupta wrote:
> 
> > i wanted to disable dynamic mapping for my indices.. but it is somehow  
> > not working for me.. i looked at the documentation and im still getting  
> > confused.. tried couple of things and it didnt work.
> > 
> > does anyone have a working example?
> > 
> > e.g., i tried the below and that didnt work -  
> > { "number\_of\_shards" : 2,  
> > "mapper.dynamic" : false  
> > }
> > 
> > i looked at this link -  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> > 
> > it doesnt really tell how to disable at root level.
> > 
> > thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![hazzadous](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hazzadous/32/1654_2.png) [@hazzadous](https://discuss.elastic.co/u/hazzadous)
#### Post date: [February 21, 2013, 10:10am UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping/10659/6 "2013-02-21T10:10:58Z")

</div>

In this case, you can specify dynamic: "strict". Any attempt to index an  
unmapped field will cause the op to fail.

On Wednesday, 20 February 2013 17:25:47 UTC, Christopher J. Bottaro wrote:

> How about if I want an error raised if I try to index a field that's not  
> defined as a part of the mapping?
> 
> Thanks.
> 
> On Friday, February 8, 2013 4:15:14 AM UTC-6, Michael Kleen wrote:
> 
> > Hello,
> > 
> > if you want to disable the dynamic mapping on the root level of your  
> > object as you asked for and not on the complete index as Radu mentioned  
> > you can do it in the following way:
> > 
> > [https://gist.github.com/mkleen/4942355b8af22daa4a4e](https://gist.github.com/mkleen/4942355b8af22daa4a4e)
> > 
> > This will not prevent that an object gets created with unmapped fields,  
> > but it wont create a dynamic field in the index as shown above in the  
> > example.
> > 
> > Regards,
> > 
> > Michael
> > 
> > On Thursday, February 7, 2013 11:17:30 PM UTC+1, T Vinod Gupta wrote:
> > 
> > > i wanted to disable dynamic mapping for my indices.. but it is somehow  
> > > not working for me.. i looked at the documentation and im still getting  
> > > confused.. tried couple of things and it didnt work.
> > > 
> > > does anyone have a working example?
> > > 
> > > e.g., i tried the below and that didnt work -  
> > > { "number\_of\_shards" : 2,  
> > > "mapper.dynamic" : false  
> > > }
> > > 
> > > i looked at this link -  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> > > 
> > > it doesnt really tell how to disable at root level.
> > > 
> > > thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Christopher\_J\_Bottar](https://avatars.discourse-cdn.com/v4/letter/c/e0b2c6/32.png) [@Christopher\_J\_Bottar](https://discuss.elastic.co/u/Christopher_J_Bottar)
#### Post date: [February 22, 2013, 3:53pm UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping/10659/7 "2013-02-22T15:53:13Z")

</div>

In the yaml config file? Or is it a part of an index's mapping? Can you  
give an example of how to use that setting?

Thanks for the info.

On Thursday, February 21, 2013 4:10:58 AM UTC-6, hazzadous wrote:

> In this case, you can specify dynamic: "strict". Any attempt to index an  
> unmapped field will cause the op to fail.
> 
> On Wednesday, 20 February 2013 17:25:47 UTC, Christopher J. Bottaro wrote:
> 
> > How about if I want an error raised if I try to index a field that's not  
> > defined as a part of the mapping?
> > 
> > Thanks.
> > 
> > On Friday, February 8, 2013 4:15:14 AM UTC-6, Michael Kleen wrote:
> > 
> > > Hello,
> > > 
> > > if you want to disable the dynamic mapping on the root level of your  
> > > object as you asked for and not on the complete index as Radu mentioned  
> > > you can do it in the following way:
> > > 
> > > [https://gist.github.com/mkleen/4942355b8af22daa4a4e](https://gist.github.com/mkleen/4942355b8af22daa4a4e)
> > > 
> > > This will not prevent that an object gets created with unmapped fields,  
> > > but it wont create a dynamic field in the index as shown above in the  
> > > example.
> > > 
> > > Regards,
> > > 
> > > Michael
> > > 
> > > On Thursday, February 7, 2013 11:17:30 PM UTC+1, T Vinod Gupta wrote:
> > > 
> > > > i wanted to disable dynamic mapping for my indices.. but it is somehow  
> > > > not working for me.. i looked at the documentation and im still getting  
> > > > confused.. tried couple of things and it didnt work.
> > > > 
> > > > does anyone have a working example?
> > > > 
> > > > e.g., i tried the below and that didnt work -  
> > > > { "number\_of\_shards" : 2,  
> > > > "mapper.dynamic" : false  
> > > > }
> > > > 
> > > > i looked at this link -  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> > > > 
> > > > it doesnt really tell how to disable at root level.
> > > > 
> > > > thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [February 22, 2013, 4:38pm UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping/10659/8 "2013-02-22T16:38:19Z")

</div>

On Fri, 2013-02-22 at 07:53 -0800, Christopher J. Bottaro wrote:

> In the yaml config file? Or is it a part of an index's mapping? Can  
> you give an example of how to use that setting?

You can use it when you specify the mapping, eg at index creation time:

curl -XPUT '[http://127.0.0.1:9200/test/?pretty=1](http://127.0.0.1:9200/test/?pretty=1)' -d '  
{  
"mappings" : {  
"mytype" : {  
"dynamic" : "strict",  
"properties" : {  
"foo" : {  
"type" : "string"  
}  
}  
}  
}  
}  
'

You can also set it for all types in an index by specifying the default  
mapping:

curl -XPUT '[http://127.0.0.1:9200/test/?pretty=1](http://127.0.0.1:9200/test/?pretty=1)' -d '  
{  
"mappings" : {  
"_default_" : {  
"dynamic" : "strict"  
}  
}  
}  
'

clint

> Thanks for the info.
> 
> On Thursday, February 21, 2013 4:10:58 AM UTC-6, hazzadous wrote:  
> In this case, you can specify dynamic: "strict". Any attempt  
> to index an unmapped field will cause the op to fail.
> 
> ```
> On Wednesday, 20 February 2013 17:25:47 UTC, Christopher J.
> Bottaro wrote:
> How about if I want an error raised if I try to index
> a field that's not defined as a part of the mapping?
>             
>             
> Thanks.
>             
> On Friday, February 8, 2013 4:15:14 AM UTC-6, Michael
> Kleen wrote:
> Hello, 
>                     
>                     
> if you want to disable the dynamic mapping on
> the root level of your object as you asked for
> and not on the complete index
> as Radu mentioned you can do it in the
> following way:
>                     
>                     
> https://gist.github.com/mkleen/4942355b8af22daa4a4e
>                     
>                     
>                     
> This will not prevent that an object gets
> created with unmapped fields, but it wont
> create a dynamic field in the index as shown
> above in the example. 
>                     
>                     
> Regards,
>                     
>                     
> Michael
>                     
> On Thursday, February 7, 2013 11:17:30 PM UTC
> +1, T Vinod Gupta wrote:
> i wanted to disable dynamic mapping
> for my indices.. but it is somehow not
> working for me.. i looked at the
> documentation and im still getting
> confused.. tried couple of things and
> it didnt work.
>                             
>                             
> does anyone have a working example?
>                             
>                             
> e.g., i tried the below and that didnt
> work - 
> { "number_of_shards" : 2,
> "mapper.dynamic" : false
> }
>                             
>                             
> i looked at this link
> - http://www.elasticsearch.org/guide/reference/mapping/object-type.html
>                             
>                             
> it doesnt really tell how to disable
> at root level.
>                             
>                             
> thanks 
> 
> ```
> 
> --  
> You received this message because you are subscribed to the Google  
> Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send  
> an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Teddy777](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@Teddy777](https://discuss.elastic.co/u/Teddy777)
#### Post date: [February 22, 2013, 5:36pm UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping/10659/9 "2013-02-22T17:36:31Z")

</div>

If I want to specify my own mapping for some fields yet would like the  
dynamic mapper to pick up on fields that I haven't specified, is this  
possible?

On Thursday, 7 February 2013 22:17:30 UTC, T Vinod Gupta wrote:

> i wanted to disable dynamic mapping for my indices.. but it is somehow not  
> working for me.. i looked at the documentation and im still getting  
> confused.. tried couple of things and it didnt work.
> 
> does anyone have a working example?
> 
> e.g., i tried the below and that didnt work -  
> { "number\_of\_shards" : 2,  
> "mapper.dynamic" : false  
> }
> 
> i looked at this link -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)
> 
> it doesnt really tell how to disable at root level.
> 
> thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [February 22, 2013, 5:49pm UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping/10659/10 "2013-02-22T17:49:19Z")

</div>

On Fri, 2013-02-22 at 09:36 -0800, Teddy777 wrote:

> If I want to specify my own mapping for some fields yet would like the  
> dynamic mapper to pick up on fields that I haven't specified, is this  
> possible?

Yes, just put the mapping with the fields you want to specify, and leave  
it as the default of dynamic: true. Then any new fields will by  
dynamically detected and added

clint

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:50am UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping/10659/11 "2017-07-06T02:50:01Z")

</div>


