Using the IndexCustodian class for index operations

Abstract

This topic describes how you use the IndexCustodian class for index operations instead of the ISearchIndex interface.

We highly recommended that you use the IndexCustodian class for index operations instead of the ISearchIndex interface. The ISearchIndex interface contains the following API calls for index operations:

  • Rebuild

  • Update

  • Delete

  • Refresh

When you invoke these methods directly on the ISearchIndex interface, it can cause various issues ranging from missing log entries to application crash due to a StackOverflowException exception. Therefore, use these API calls from the IndexCustodian class. When you use the IndexCustodian class, the following things are different from the ISearchIndex interface:

  • The  IndexCustodian class runs the index operation in the context of a job. This ensures that the operation is atomic: no other rebuild or update operations can run for the same search index simultaneously.

  • The  IndexCustodian class triggers the indexing:start and indexing:end events. Sitecore relies on the events to keep instances in sync, and it also uses events to process some local changes.