# Is there a way to prevent that new fields are added to a schema during document ingestion via API?

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-prevent-that-new-fields-are-added-to-a-schema-during-document-ingestion-via-api/270373>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [April 16, 2021, 10:27am UTC](https://discuss.elastic.co/t/is-there-a-way-to-prevent-that-new-fields-are-added-to-a-schema-during-document-ingestion-via-api/270373 "2021-04-16T10:27:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ralph2021](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@Ralph2021](https://discuss.elastic.co/u/Ralph2021)\
**Post date:** [April 16, 2021, 10:27am UTC](https://discuss.elastic.co/t/is-there-a-way-to-prevent-that-new-fields-are-added-to-a-schema-during-document-ingestion-via-api/270373/1 "2021-04-16T10:27:43Z")

</div>

On a regular basis we see fields appearing in a schema that should not be there. The cause is that if a developer starts ingesting documents they may use the fields or make a typo. The result is that new fields are created. Is there a way we can present this? I would rather have the API throw an error if the fields don't match the schema.

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [April 16, 2021, 1:00pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-prevent-that-new-fields-are-added-to-a-schema-during-document-ingestion-via-api/270373/2 "2021-04-16T13:00:17Z")

</div>

Hi @Ralph2021

Absolutely see the documentation [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-field-mapping.html#dynamic-field-mapping) on dynamic mapping.

You will set `dynamic` to `strict` see [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic.html#dynamic-parameters)

_If new fields are detected, an exception is thrown and the document is rejected. New fields must be explicitly added to the mapping._

---

<div class="post-metadata">

**Author:** ![JonasLavoie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonaslavoie/32/56961_2.png) [@JonasLavoie](https://discuss.elastic.co/u/JonasLavoie)\
**Post date:** [April 16, 2021, 3:28pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-prevent-that-new-fields-are-added-to-a-schema-during-document-ingestion-via-api/270373/3 "2021-04-16T15:28:34Z")

</div>

Hey Ralph!

Stephen is correct if you are using Elasticsearch directly today, but it seems like you may be using App Search, in which case the behavior you are describing is expected, and Stephen’s approach won’t apply to your situation.

This is a very valid product enhancement idea and valuable feedback for App Search, and I’ll make sure to convey this information to the relevant teams!

For the time being, best practices of enforcing schema at the data source level still applies, if you are able to do so.

We’re here to help should something else arise!

---

<div class="post-metadata">

**Author:** ![Ralph2021](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@Ralph2021](https://discuss.elastic.co/u/Ralph2021)\
**Post date:** [April 16, 2021, 5:18pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-prevent-that-new-fields-are-added-to-a-schema-during-document-ingestion-via-api/270373/4 "2021-04-16T17:18:20Z")

</div>

Thanks for the response Jonas and Stephen. This is indeed an App Search case. A simple toggle on engine level to prohibit the creation of extra fields via the documents API would do the trick. Being able to control this with a flag like 'strict' in the API will also help but then we are dependent on the developers to stick to the schema (or make strict the default). We do ask that but in reality we see that too often they make mistakes here. Especially in non-prod environments where new feeds are being developed.

---

<div class="post-metadata">

**Author:** ![JonasLavoie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonaslavoie/32/56961_2.png) [@JonasLavoie](https://discuss.elastic.co/u/JonasLavoie)\
**Post date:** [April 16, 2021, 5:31pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-prevent-that-new-fields-are-added-to-a-schema-during-document-ingestion-via-api/270373/5 "2021-04-16T17:31:11Z")

</div>

Makes sense - thanks for taking the time to clearly outline the use case here, this is helpful.

Let us know if anything else is on your mind

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [April 16, 2021, 9:46pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-prevent-that-new-fields-are-added-to-a-schema-during-document-ingestion-via-api/270373/6 "2021-04-16T21:46:04Z")

</div>

@Ralph2021 @JonasLavoie

Thanks for clarifying that apologies for not reading the post / tags well enough!

---

<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:** [May 14, 2021, 9:46pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-prevent-that-new-fields-are-added-to-a-schema-during-document-ingestion-via-api/270373/7 "2021-05-14T21:46:05Z")

</div>

Closed on May 14, 2021, 9:46pm UTC

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