Sometimes you need reindex an item but you don’t want to rebuild the whole index. 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]$_)
}
}
Hope it helps!
Happy scripting.