# Define required fields in the mapping

**URL:** <https://discuss.elastic.co/t/define-required-fields-in-the-mapping/13089>\
**Category:** Elasticsearch\
**Created:** [August 6, 2013, 1:14pm UTC](https://discuss.elastic.co/t/define-required-fields-in-the-mapping/13089 "2013-08-06T13:14:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kristi](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kristi](https://discuss.elastic.co/u/Kristi)\
**Post date:** [August 6, 2013, 1:14pm UTC](https://discuss.elastic.co/t/define-required-fields-in-the-mapping/13089/1 "2013-08-06T13:14:09Z")

</div>

Is it possible to define required fields in the mapping, so an attempt to  
index a document that's missing the fields would throw an error?

--  
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:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [August 6, 2013, 2:11pm UTC](https://discuss.elastic.co/t/define-required-fields-in-the-mapping/13089/2 "2013-08-06T14:11:12Z")

</div>

Elasticsearch can be prevented from automatically creating an index and  
automatically indexing unknown fields by updating the elasticsearch.ymlfile as follows:

action.auto\_create\_index: false  
index.mapper.dynamic: false

The ability to disable automatic index creation and dynamic mapping is in  
Elasticsearch versions 0.20.X and later.

Brian

On Tuesday, August 6, 2013 9:14:09 AM UTC-4, Kristi wrote:

> Is it possible to define required fields in the mapping, so an attempt to  
> index a document that's missing the fields would throw an error?

--  
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:** ![brian\_yoder](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@brian\_yoder](https://discuss.elastic.co/u/brian_yoder)\
**Post date:** [August 6, 2013, 2:13pm UTC](https://discuss.elastic.co/t/define-required-fields-in-the-mapping/13089/3 "2013-08-06T14:13:00Z")

</div>

Almost forget: With this, you'll need to explicitly create an index with  
the mappings you need, along with whatever filters those mappings require.

Brian

On Tuesday, August 6, 2013 10:11:12 AM UTC-4, InquiringMind wrote:

> Elasticsearch can be prevented from automatically creating an index and  
> automatically indexing unknown fields by updating the elasticsearch.ymlfile as follows:
> 
> action.auto\_create\_index: false  
> index.mapper.dynamic: false
> 
> The ability to disable automatic index creation and dynamic mapping is in  
> Elasticsearch versions 0.20.X and later.
> 
> Brian
> 
> On Tuesday, August 6, 2013 9:14:09 AM UTC-4, Kristi wrote:
> 
> > Is it possible to define required fields in the mapping, so an attempt to  
> > index a document that's missing the fields would throw an error?

--  
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:** ![Kristi](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kristi](https://discuss.elastic.co/u/Kristi)\
**Post date:** [August 6, 2013, 3:09pm UTC](https://discuss.elastic.co/t/define-required-fields-in-the-mapping/13089/4 "2013-08-06T15:09:28Z")

</div>

Thank you for your response. However, I don't think this does what I  
want. It's fine if unknown fields are automatically indexed, I don't want  
to prevent that. I was wondering if it's possible to define in the mapping  
that some fields are required. For example, you define a field called  
"title", and you want all documents that are indexed to have the "title"  
field. Is it possible to configure Elasticsearch to validate that this  
field is in the document when you index it, and throw an error if it is  
missing?

I think in Solr, you can just add required="true" to the schema.xml when  
you define the fields for a type. Is there a way to do this in  
Elasticsearch?

On Tuesday, August 6, 2013 2:13:00 PM UTC, InquiringMind wrote:

> Almost forget: With this, you'll need to explicitly create an index with  
> the mappings you need, along with whatever filters those mappings require.
> 
> Brian
> 
> On Tuesday, August 6, 2013 10:11:12 AM UTC-4, InquiringMind wrote:
> 
> > Elasticsearch can be prevented from automatically creating an index and  
> > automatically indexing unknown fields by updating the elasticsearch.ymlfile as follows:
> > 
> > action.auto\_create\_index: false  
> > index.mapper.dynamic: false
> > 
> > The ability to disable automatic index creation and dynamic mapping is in  
> > Elasticsearch versions 0.20.X and later.
> > 
> > Brian
> > 
> > On Tuesday, August 6, 2013 9:14:09 AM UTC-4, Kristi wrote:
> > 
> > > Is it possible to define required fields in the mapping, so an attempt  
> > > to index a document that's missing the fields would throw an error?

--  
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:22am UTC](https://discuss.elastic.co/t/define-required-fields-in-the-mapping/13089/5 "2017-07-06T02:22:39Z")

</div>


