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