We are using Azure Search on Sitecore 8.2 update 7 and have enabled switch on rebuild.
This is documented here: https://doc.sitecore.com/developers/91/platform-administration-and-architecture/en/zero-downtime-index-rebuild-in-azure-search.html
Use the Azure Search Switch On Rebuild feature to avoid Search functionality downtime during a full rebuild of the Sitecore Search index.
The issue we are seeing is that when the index is rebuilt (e.g 'my-custom-web-index') it is renamed to 'my-custom-web-index-secondary'. And we are referencing it by name as 'my-custom-web-index' when querying it using the content search API, this then results in not being able to find the index and therefore returning no results - since it is now called 'my-custom-web-index-secondary'.
My understanding is that the primary index name is stored in the Core database: How is the name of the primary index name stored when using SwitchOnRebuild in Azure Search?
The explanation of how switch on rebuild works is as follows:
After a power user requests a full rebuild of the Sitecore Search index(es), the following process takes place:
The Sitecore Azure Search provider creates a new index for the full rebuild operation.
While Sitecore writes data into the new index, the search provider continues to use the old one.
When the full rebuild is complete, the Sitecore Azure Search provider sends a corresponding remote event (index:switchonrebuild) to all roles.
Each role processes the remote 'index:switchonrebuild' event and switches the search service over to work with the newly rebuilt index.
The SwitchOnRebuildCleanUpDelay setting controls the delay that allows other roles to process the remote event and switch index.
After the time-buffer delay runs out (controlled by the SwitchOnRebuildCleanUpDelay setting), and the rebuilt index becomes the primary search index, Sitecore deletes the previous search index. This delay allows the other roles time to process the remote event and switch indexes.
However this doesn't really explain what the index is renamed to.
Does the name of the index bounce between 'my-custom-web-index-secondary' and 'my-custom-web-index' each time it's rebuilt?
Is this the expected functionality? and if so how do I go about querying it using the content search API?
I had a discussion in Slack with Peter Rydetorp and he suggested that CloudSearchProviderIndex has an GetCloudIndexName method which I could potentially use to get the index name but I'm not quite sure how to go about this.