Elastic Search Index

Sonarqube showing incorrect count of issues on dashboard - SonarQube - Sonar Community (sonarsource.com)
i found a topic where they suggested the same option of deleting /data/es and restarting the server.
Julien Lancelot and Nicolas Bontoux suggested the way .
so i would like to know a way to automate this process, rather than doing it manually.
Regards