Please format your code using </>
icon as explained in this guide. It will make your post more readable.
It seems that the mapping has not been processed on every shard in the same manner. IIRC it can happen on old version when 2 requests goes to 2 shards in parallel and updates the mapping at the same time.
This has been fixed in recent version.
I don't know how you can identify this though.
A way to solve the issue in the future, may be send the mapping in advance when you create your index so you are sure it's propagated to all nodes/shards.
Or upgrade