Mapper_parsing_exception set value by default

I am looking for some script or configuration in order to set a value of a field after an error appears. In my case mapper_parsing_exception.
In other words, If I have a value "N/A" it will get an mapper_parsing_exception because this field is waiting for a LONG (number) so I would like to automatically change the "N/A" to 0. Is it possible ???

Thanks!

5.0 will make it possible with ingest pipelines, however in the current stable version there is no way to do it. The closest option I can think of would be to pass null rather than "N/A" and configuring a null_value in the mappings.

Yes, but I am not able to change the "N/A" to null. When I said N/A i meant any string . I am looking to change any value to 0 if the value is an string which means N/A, BLABLABLA; WHATEVER, etc.

what about a groovy script? Can I write a script which verify a value and change it to a number before inserting a document?

Thanks

Maybe you could do this by using the update API rather than the index APIs: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html#_literal_scripted_upsert_literal