I suggest using Spring Data Elasticsearch for Elasticsearch 8.x configuration-related tasks. I've attached the GitHub link for the Elasticsearch configuration below.
I hope this helps!