# Possibility to constrain certain field(s) as mandatory field(s)

**URL:** <https://discuss.elastic.co/t/possibility-to-constrain-certain-field-s-as-mandatory-field-s/11975>\
**Category:** Elasticsearch\
**Created:** [May 15, 2013, 1:21pm UTC](https://discuss.elastic.co/t/possibility-to-constrain-certain-field-s-as-mandatory-field-s/11975 "2013-05-15T13:21:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AshutoshB](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashutoshb/32/28577_2.png) [@AshutoshB](https://discuss.elastic.co/u/AshutoshB)\
**Post date:** [May 15, 2013, 1:21pm UTC](https://discuss.elastic.co/t/possibility-to-constrain-certain-field-s-as-mandatory-field-s/11975/1 "2013-05-15T13:21:49Z")

</div>

Hi All,

We are using elastic-search for our project. We would like to implement a  
feature in our project using elastic search.

We want to make sure that all the saved documents in our project must  
contain certain field(s) e.g.  
{

USER\_ID:"123"  
USER\_NAME:"Ashutosh"

}

In other words, if the document does not contain the mandatory fields e.g.  
USER\_ID, it will not be saved.

It will be helpful, if you share your ideas whether it is possible to  
define mandatory filed(s) of a document in elastic search?

Thanks for your help.

Best,  
Ashutosh

--  
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:** [May 15, 2013, 1:24pm UTC](https://discuss.elastic.co/t/possibility-to-constrain-certain-field-s-as-mandatory-field-s/11975/2 "2013-05-15T13:24:45Z")

</div>

Hiya

This will have to be handled in your application

clint

On 15 May 2013 15:21, Ashutosh Bhattacharya \<  
[ashutosh.bhattacharya.in@gmail.com](mailto:ashutosh.bhattacharya.in@gmail.com)\> wrote:

> Hi All,
> 
> We are using elastic-search for our project. We would like to implement a  
> feature in our project using Elasticsearch.
> 
> We want to make sure that all the saved documents in our project must  
> contain certain field(s) e.g.  
> {
> 
> USER\_ID:"123"  
> USER\_NAME:"Ashutosh"
> 
> }
> 
> In other words, if the document does not contain the mandatory fields e.g.  
> USER\_ID, it will not be saved.
> 
> It will be helpful, if you share your ideas whether it is possible to  
> define mandatory filed(s) of a document in Elasticsearch?
> 
> Thanks for your help.
> 
> Best,  
> Ashutosh
> 
> --  
> 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:** ![AshutoshB](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashutoshb/32/28577_2.png) [@AshutoshB](https://discuss.elastic.co/u/AshutoshB)\
**Post date:** [May 15, 2013, 1:32pm UTC](https://discuss.elastic.co/t/possibility-to-constrain-certain-field-s-as-mandatory-field-s/11975/3 "2013-05-15T13:32:27Z")

</div>

Hi Clinton,

Thank you for your quick response. Presently, we are handling it in our  
application but it would have been better for us if we could have difined  
some kind of mappiing for the elasticsearch index to make the fielad(s)  
mandatory.

Regards,  
Ashutosh

On Wed, May 15, 2013 at 3:24 PM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> Hiya
> 
> This will have to be handled in your application
> 
> clint
> 
> On 15 May 2013 15:21, Ashutosh Bhattacharya \<  
> [ashutosh.bhattacharya.in@gmail.com](mailto:ashutosh.bhattacharya.in@gmail.com)\> wrote:
> 
> > Hi All,
> > 
> > We are using elastic-search for our project. We would like to implement a  
> > feature in our project using Elasticsearch.
> > 
> > We want to make sure that all the saved documents in our project must  
> > contain certain field(s) e.g.  
> > {
> > 
> > USER\_ID:"123"  
> > USER\_NAME:"Ashutosh"
> > 
> > }
> > 
> > In other words, if the document does not contain the mandatory fields  
> > e.g. USER\_ID, it will not be saved.
> > 
> > It will be helpful, if you share your ideas whether it is possible to  
> > define mandatory filed(s) of a document in Elasticsearch?
> > 
> > Thanks for your help.
> > 
> > Best,  
> > Ashutosh
> > 
> > --  
> > 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).

--  
Best,  
Ashutosh Bhattacharya  
Kreutzer Str. 4  
50672 Köln, Deutschland

Mob : (0049) 0151 29475229  
Email: [ashutosh.bhattacharya.in@gmail.com](mailto:ashutosh.bhattacharya.in@gmail.com)

--  
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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [May 16, 2013, 5:04am UTC](https://discuss.elastic.co/t/possibility-to-constrain-certain-field-s-as-mandatory-field-s/11975/4 "2013-05-16T05:04:32Z")

</div>

The best you can do is reject any documents with fields not explicitly  
declared in your mapping. Like Clinton said, mandatory fields are best  
handled at the client side.

--  
Ivan

On Wed, May 15, 2013 at 6:32 AM, Ashutosh Bhattacharya \<  
[ashutosh.bhattacharya.in@gmail.com](mailto:ashutosh.bhattacharya.in@gmail.com)\> wrote:

> Hi Clinton,
> 
> Thank you for your quick response. Presently, we are handling it in our  
> application but it would have been better for us if we could have difined  
> some kind of mappiing for the elasticsearch index to make the fielad(s)  
> mandatory.
> 
> Regards,  
> Ashutosh
> 
> On Wed, May 15, 2013 at 3:24 PM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:
> 
> > Hiya
> > 
> > This will have to be handled in your application
> > 
> > clint
> > 
> > On 15 May 2013 15:21, Ashutosh Bhattacharya \<  
> > [ashutosh.bhattacharya.in@gmail.com](mailto:ashutosh.bhattacharya.in@gmail.com)\> wrote:
> > 
> > > Hi All,
> > > 
> > > We are using elastic-search for our project. We would like to implement  
> > > a feature in our project using Elasticsearch.
> > > 
> > > We want to make sure that all the saved documents in our project must  
> > > contain certain field(s) e.g.  
> > > {
> > > 
> > > USER\_ID:"123"  
> > > USER\_NAME:"Ashutosh"
> > > 
> > > }
> > > 
> > > In other words, if the document does not contain the mandatory fields  
> > > e.g. USER\_ID, it will not be saved.
> > > 
> > > It will be helpful, if you share your ideas whether it is possible to  
> > > define mandatory filed(s) of a document in Elasticsearch?
> > > 
> > > Thanks for your help.
> > > 
> > > Best,  
> > > Ashutosh
> > > 
> > > --  
> > > 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).
> 
> --  
> Best,  
> Ashutosh Bhattacharya  
> Kreutzer Str. 4  
> 50672 Köln, Deutschland
> 
> Mob : (0049) 0151 29475229  
> Email: [ashutosh.bhattacharya.in@gmail.com](mailto:ashutosh.bhattacharya.in@gmail.com)
> 
> --  
> 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:** ![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:36am UTC](https://discuss.elastic.co/t/possibility-to-constrain-certain-field-s-as-mandatory-field-s/11975/5 "2017-07-06T02:36:26Z")

</div>


