Outdated dynamic field mapping

I have a dynamic field mapping of type X, and when I attempt to index a document with a different type for the same field, I get the following error with a 400 status code, as expected:

"type": "mapper_parsing_exception",
"reason": "failed to parse field [dynamic.X] of type [Y]..."

To be able to index the new document, I need to remove the existing mapping for the field, reindex into a new index with the updated mapping, and retry the document indexing, as described by https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html#updating-field-mappings

Some ways of achieving this:
1)Check at the application level if the new document field type is compatible with the existing mapping before indexing. This is not straightforward.
2)Inspect the indexing error response, extract the name of the failing field, remove it from the mappings, and reindex before retrying the indexing. This is simpler but fragile since it relies on the error response message.

Is there a cleaner recommended way to deal with this scenario?

Elasticsearch version: 7.10.1

Welcome to our community! :smiley:

You could go back to the app that is generating the data and forcing it to remain the same there. But otherwise, those two are the best approaches

1 Like

Thank you Mark.
Unfortunately it's not possible to force the data to remain the same in this case, since I have a requirement to be able to update the type of a field.

I did just remember, you could try this as well coerce | Elasticsearch Guide [7.16] | Elastic