In one of my projects, I came across the same requirement. Here is my solution:
- Create a configuration content item with a template that has only one field, for example, " Restructuring Index ", the default value is "1", an example of the path of the item could be: " / sitecore / content / mysite / config / index rebuild flag
- Create an IndexRebuilder class with the Run method. In the Run method, select the " index rebuild index " checkbox (from the Context database) and rebuild the index on the server if the value of the Restore index field is "1". After successful recovery, update the item field value to "0".
Configure a designated agent that points to the IndexRebuilder class. For instance,
<agent type = "MyAssembly.IndexRebuilder, MyAssembly" method = "Run" interval = "00:00:00" />
Please note that the interval β00:00:00β by default disables the agent on the content management server. The build and deployment process must include this value to say β00:05:00,β which allows the agent to run every 5 minutes.
From there, to rebuild the index on the content delivery server, simply publish the " index rebuild flag " element from the main database to the content delivery database (network), and the index on the content delivery server should start recovery in 5 minutes.
source share