Is there a way to automatically apply a mapping?

Currently I have an API that on initialization checks if my index exists, if not it creates it and applies my mapping, then allows the client to index documents. By and large this works well however sometimes we run into an issue where the index is purged from the system while processes are still indexing. This causes the index to be created but with no mapping so ES guesses at the mapping (uses defaults like text where I want keywords).

I don't want to add logic to check the index mapping is correct before every index request, and that wouldn't work 100% of the time anyway. Is there some way to make the index get created with the correct mapping on index (as well as my other features - shard count, replica count, etc...)? I imagine this is a semi-common problem when folks don't have the ability to stop all publishers when an index needs purged. If possible I'd like to be able to do this from the client as not all indexes have the same mapping.

Thanks!!!

Yes , you can use index template for the same .
Kindly read more about the same : Index templates | Elasticsearch Guide [8.1] | Elastic

Not sure how you can do it from client side , but in es you can define multiple templates based on index patterns if you want.

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