# Returning error when trying to insert document with non-existent field

**URL:** <https://discuss.elastic.co/t/returning-error-when-trying-to-insert-document-with-non-existent-field/110559>\
**Category:** Elasticsearch\
**Created:** [December 6, 2017, 6:35pm UTC](https://discuss.elastic.co/t/returning-error-when-trying-to-insert-document-with-non-existent-field/110559 "2017-12-06T18:35:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nadiGam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nadigam/32/124078_2.png) [@nadiGam](https://discuss.elastic.co/u/nadiGam)\
**Post date:** [December 6, 2017, 6:35pm UTC](https://discuss.elastic.co/t/returning-error-when-trying-to-insert-document-with-non-existent-field/110559/1 "2017-12-06T18:35:33Z")

</div>

For example , I want to insert new document which consist of two strings into myindex/mytype  
{  
"name" : "joe",  
"city": "ny"  
}

BUT mytype consist only of one string field : "name"

in this case I want the indexing to fail, and that elasticsearch return an error. How do I do that ?  
Right now it creates new document ☹

Thanls for your help !

---

<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:** [January 3, 2018, 6:35pm UTC](https://discuss.elastic.co/t/returning-error-when-trying-to-insert-document-with-non-existent-field/110559/2 "2018-01-03T18:35:33Z")

</div>

Closed on January 3, 2018, 6:35pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
