How can i rebuild all search indices through api

I would like to have the functionality found in Litium backoffice to rebuild and/or update search indexes for all or specific areas through API, is there an easy way to do this?

You can trigger the search index rebuild with the following code.

ModuleCMS.Instance.PageIndexingService.QueueIndexRebuild(Solution.Instance.SystemToken, true);
ModuleECommerce.Instance.OrderIndexingService.QueueIndexRebuild(Solution.Instance.SystemToken, true);
ModuleProductCatalog.Instance.CategoryIndexingService.QueueIndexRebuild(Solution.Instance.SystemToken, true);
ModuleProductCatalog.Instance.ProductIndexingService.QueueIndexRebuild(Solution.Instance.SystemToken, true);
1 Like

@patric.forsgard Is there a way to identify if search index needs a rebuild?
If we for example reinstall a machine, then the search index will be empty. We want to automatically trigger a rebuild.

You can use the Solution.Instance.SearchConfigurationService.GetIndexSize("indexname") to see if you have any data in the search index. If the index size is small the index is probably missing or the index should only contains limited amount of items.

1 Like