Monday, August 14, 2023

How to rebuild the Solr index using PowerShell script?


This blog will help you rebuild the Solr index using the PowerShell script more efficiently. 

The following code snippet will help to reindex a specific item instead of rebuilding the whole index programmatically using the PowerShell script.

This code should work with any version of Sitecore. 

Open - Development Tools -> PowerShell ISE and paste the following code.

Modify the paths and fields according to your template fields, if required.


Reindex specific data items for the particular index

PowerShell script code:    

[Sitecore.ContentSearch.ContentSearchManager]::Indexes | Foreach-Object { $options.Add($_.Name, $_.Name) } 

$props = @{ 
    Parameters = @( 
        @{Name="indexName"; Title="Choose an index"; Options=$options; Tooltip="Choose Index"} 
    ) 
    Title = "Index Wizard" 
    Description = "Select an index." 
    Width = 300 
    Height = 300 
    ShowHints = $true 
} 

$result = Read-Variable @props 

if ($result -eq "ok") { 
    $index = [Sitecore.ContentSearch.ContentSearchManager]::GetIndex($indexName) 
} 

Close-Window 
  

Get-ChildItem -path "/sitecore/content/Home/" -language en-Us -Recurse | Where-Object { $_.TemplateName -eq 'Article'  } | ForEach-Object { 

    if([string]::IsNullOrEmpty($_."Any Field")){ 
        write-host $_.Name "SKIPPED" 
    } 
    else{ 
         write-host $_.Name $_.Paths.FullPath 
       [Sitecore.ContentSearch.Maintenance.IndexCustodian]::Refresh($index, [Sitecore.ContentSearch.SitecoreIndexableItem]$_) 
    }      

} 


How to Create a Public Link Using the Sitecore Content Hub REST API

Creating a public link using the Sitecore Content Hub REST API is a straightforward process that enables you to share content externally whi...