Deleting and recreating the SharePoint search index

If left on its own, the SharePoint on-prem search index will grow in size, seemingly, forever. When my server disk gets to around only 20Gb free, the search crawl will run forever, until I stop it. A couple of blog posts helped me delete and recreate the index.

See https://vigneshsharepointthoughts.com/2016/12/15/resetting-search-index-in-sharepoint-2013/ and http://jcaspadmin.blogspot.com/2014/05/sharepoint-2013-content-index-reset.html. The following PowerShell script will stop all crawls, stop the enterprise search service, delete the index, and start the search service again. For now, just before I delete the index, I must manually delete all the XML files in C:\ProgramData\Microsoft\SharePoint\Config\2cc50e6c-dacd-43ad-934f-f4809bb59f70

$sargent = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application I" -Identity "Local SharePoint Sites"
$LMS = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application I" -Identity "LMS"
$onerbc = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application I" -Identity "MySites"
$mySites = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application I" -Identity "ONERBC"
$userProfiles = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application I" -Identity "User Profiles"

if ( $sargent.CrawlStatus -ne "Idle" ){ $sargent.StopCrawl()}
if ( $LMS.CrawlStatus -ne "Idle" ){$LMS.StopCrawl()}
if ( $onerbc.CrawlStatus -ne "Idle" ){$onerbc.StopCrawl()}
if ( $mySites.CrawlStatus -ne "Idle" ){$mySites.StopCrawl()}
if ( $userProfiles.CrawlStatus -ne "Idle" ){$userProfiles.StopCrawl()}
do {
    Write-Host "SARGENT Crawl Status is " $sargent.CrawlStatus
} until ($sargent.CrawlStatus -eq "Idle")
do {
    Write-Host "LMS Crawl Status is " $userProfiles.CrawlStatus
} until ($LMS.CrawlStatus -eq "Idle")
do {
    Write-Host "ONERBC Crawl Status is " $onerbc.CrawlStatus
} until ($onerbc.CrawlStatus -eq "Idle")
do {
    Write-Host "My Sites Crawl Status is " $mySites.CrawlStatus
} until ($mySites.CrawlStatus -eq "Idle")
do {
    Write-Host "User Profiles Crawl Status is " $userProfiles.CrawlStatus
} until ($userProfiles.CrawlStatus -eq "Idle")
Write-Host "All crawls stopped."
# now all Crawls should be done.
# turn off the search service.
Suspend-SPEnterpriseSearchServiceApplication “Search Service Application I”
#pause while it stops
Start-Sleep -Seconds 120

# see http://jcaspadmin.blogspot.com/2014/05/sharepoint-2013-content-index-reset.html
# delete the index
(Get-SPEnterpriseSearchServiceApplication).reset($true, $true)
# wait 15 minutes so we're sure the index is done being deleted.
Start-Sleep -Seconds 900
# turn the search service back on.
Resume-SPEnterpriseSearchServiceApplication “Search Service Application I”

Published by Joseph LeMay

Former IBM Notes Developer, now doing SharePoint

Leave a comment