Thursday, 12 June 2025

Implementing Solr Index Switch in Sitecore During Rebuilds

We're currently working on a Sitecore 10.4 solution hosted in a Docker-based containerized environment, with Solr search integrated as part of the architecture.

While implementing custom Solr indexes, we encountered an issue in the live environment where the search functionality became unresponsive during index rebuilding. The results only started appearing again once the indexing process was complete.

To address this, I explored a few community resources and came across two helpful articles that outlined the same approach for setting up custom Solr indexes in Docker. Seeing consistency in both guides gave me the confidence to adopt the same approach for our setup. 😊


https://sitecoreblog.frankbatallas.com/2023/03/30/create-a-custom-index-in-sitecore-with-docker/

https://sitecorewithraman.wordpress.com/2022/10/02/custom-solr-core-in-sitecore-docker-and-managed-cloud/

As outlined in the blogs mentioned above, I made the following changes in the solr-init configuration to create custom indexes during initialization.

#Created a new JSON file specifying the names of our custom indexes

{

    "sitecore": [

    "_my_custom_master_index",

    "_my_custom_web_index",

          "_my_custom_web_index_rebuild" 

    ] }


#
Also added a configuration file for the indexes, structured as follows:

SitecoreSolrCustomIndexConfig

Everything was working smoothly up to this point. I was able to load the custom indexes successfully in the Sitecore Index Manager, and the index build process worked flawlessly for all the targeted templates and fields.

We then deployed these changes to the live environment, and everything appeared to be functioning well—until we attempted to trigger indexing for certain Sitecore content items. That’s when we noticed an issue: the Sitecore search results page became unresponsive, displaying the message No Results Found. (This is our default message shown when Solr returns no search results.)

We were initially unable to determine the cause of this behavior and after lot of troubleshooting we reached out to Sirecore Support with our problem. With their help, we identified the right solution using Switch Indexes on rebuild

And, these below are some steps that Sitecore suggested in CustomSolrJson:

#Advised to create one addition collecation for the index, so i have created as named sitecore_my_custom_web_index_rebuild collections.
#Created the sitecore_my_custom_web_indexMainAlias and sitecore_my_custom_web_indexRebuildAlias aliases.

#As these changes applied to SolrCloud mode so make sure you are using solrCloud mode and solrCloud set to true in solr connection string

Change for CustomSolrConfig
#Update config change to

     Sitecore.ContentSearch.SolrProvider.SwitchOnRebuildSolrCloudSearchIndex

#And add mainAlias and rebuildCollection as mentioned in below screenshot

#Populated the Solr Managed Schema.
#Rebuilt the sitecore_my_custom_web_index index. 

Above mentioned steps in sitecore documentation and sitecore support guidance helped us to fix the issue on prod as 
SwitchOnRebuildSolrCloudSearchIndex class leverages Solr collection aliases. It uses the active alias for search and update operations, and the rebuild alias during index rebuilds. Once the rebuild is complete, the CREATEALIAS command is used to swap the collections referenced by the aliases.
 










Thursday, 27 June 2024

Sitecore remote PSE error "The current user does not have write access to this item"

 Error:

Encountering a 'current user does not have write access to this item' error in Sitecore's PowerShell Extensions (SPE) can be a stumbling block when working remotely.
This error typically indicates that the user account being used for the remote session does not have the necessary permissions to modify the item.




Resolution:  

Grant Appropriate Rights: To resolve this, ensure that the user has been granted the appropriate rights through a configuration patch, as detailed in the SPE documentation. Also, check the remoting service enabled and the user account granted access to the necessary role, it is best to assign the role(sitecore\PowerShell Extensions Remoting)

Check Execution Policy: Confirm that the execution policy is set to RemoteSigned. This allows the SPE Remoting module to run, but it usually requires elevated privileges.

Fallback Option: If the above steps don’t resolve the issue, consider writing your script in SecurityDisabler mode. This will elevate the remote user’s privileges, granting read/write access to Sitecore content items remotely using PSE.

 Here’s an example PowerShell script snippet for reference:

Set-ExecutionPolicy RemoteSigned
Import-Module -Name SPE
$session = New-ScriptSession -Username remoteuser -Password b -ConnectionUri https://CM_instance_URL
Invoke-RemoteScript -ScriptBlock {
New-UsingBlock(New-Object Sitecore.SecurityModel.SecurityDisabler){
New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
$item = Get-Item -Path "master:/sitecore/content/Home/test-page"
$item.Editing.BeginEdit()
$item["Title"] = "New Title - I am testing"
$item.Editing.EndEdit()
  }
 }
} -Session $session


Remember to replace placeholders like remoteuserb, and https://CM_instance_URL with actual values relevant to your environment.
Let me know if you need further assistance! 😊