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

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.

Hi @Ralph2021

Absolutely see the documentation here on dynamic mapping.

You will set dynamic to strict see here

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

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!

1 Like

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.

1 Like

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

@Ralph2021 @JonasLavoie

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

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