1

I am trying to rebuild the SOLR indexes of a particular Sitecore item using Sitecore Powershell. I have a list of Sitecore items and I want to rebuild indexes for all items in the list. is there any way to do this?

2 Answers 2

2

Here is a handy script that will let you reindex any item on any specific index. You can also add any specific logic and it will index the items for you.

$options = @{} 

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

$props = @{ 
    Parameters = @( 
        @{Name="indexName"; Title="Choose an index"; Options=$options; Tooltip="Choose one."} 
    ) 
    Title = "Index selector" 
    Description = "Choose 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 'Product'  } | 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]$_) 
    }      

} 

Ref: https://cmsxperience.com/2023/01/05/sitecore-powershell-script-to-reindex-a-specific-item-on-a-specific-index/

Hope this helps.

1

If you have a list of items then you need to reindex the item with sub-tree so it would refresh specific items only. Sitecore has a button on the developer tab that allows you to re-index just a portion of the content tree. This can be handy to avoid a full index rebuild when you have a large content tree or if you are debugging custom indexing functionality like computed fields. Unfortunately, the button causes the the subtree to be re-indexed for all indexes.

You can use this script and create a context menu.

$item = Get-Item .
$options = @{}
[Sitecore.ContentSearch.ContentSearchManager]::Indexes | Foreach-Object { $options.Add($_.Name, $_.Name) }
$props = @{
    Parameters = @(
        @{Name="indexName"; Title="Choose an index"; Options=$options; Tooltip="Choose one."}
    )
    Title = "Index selector"
    Description = "Choose an index."
    Width = 300
    Height = 300
    ShowHints = $true
}
$result = Read-Variable @props
if ($result -eq "ok") {
    $index = [Sitecore.ContentSearch.ContentSearchManager]::GetIndex($indexName)
    [Sitecore.ContentSearch.Maintenance.IndexCustodian]::Refresh($index, [Sitecore.ContentSearch.SitecoreIndexableItem]$item)
}
Close-Window

This script lets you select one index to refresh for the selected subtree. Note that it just starts the job and closes the window. The script needs to be saved under /sitecore/system/Modules/PowerShell/Script Library/Content Editor/Context Menu after you have enabled the context menu integration point in the module.

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.