Re-index SharePoint sites
Summary
When using SharePoint columns in search solutions, you may need to map crawled properties to managed properties and update the search schema. For example, you can map the crawled property ows_Foo
to RefinableString100
and use it as a filter in KQL. For more information, refer to How Do Site Columns Become Managed Properties.
If your schema change applies to existing content, you must schedule a re-index operation for the affected content in order to have the data populated into the search index.
Important
Scheduling of re-indexing should ALWAYS happen at the smallest level possible. If affected data is in a specific library or list, then re-index ONLY the specific library. This can be achieved via the site settings in SharePoint or by using the command Request-PnPReIndexList.
Caution
The below script should ONLY be used for the scenario where a schema mapping affects ALL content in your tenant. Site re-indexing may add stress to the search system and take an extended amount of time to complete. Re-crawls of sites with more than one million items can potentially take weeks to process. Subsequent index updates could be delayed until the re-indexing is complete, leading to out-of-date search results. Make sure to only initiate a site re-index after making changes that require all items to be reindexed.
This PnP PowerShell script streamlines the process of re-indexing sites, libraries, or lists to ensure that search results remain accurate and relevant.
#Prompt for caution
Read-Host -Prompt "Are you sure you know what you are doing, and have read the text at https://pnp.github.io/script-samples/spo-reindex-sites/README.html?"
#Set Parameters
$AdminCenterURL = "https://contoso-admin.sharepoint.com"
# Connect to SharePoint admin center
Connect-PnPOnline -Url $AdminCenterURL -Interactive
#Get SharePoint sites
$m365Sites = Get-PnPTenantSite -Detailed | Where-Object {($_.Url -like '*/teams-*' -or $_.Template -eq 'TEAMCHANNEL#1') -and $_.Template -ne 'RedirectSite#0' } #filter to exclude redirect sites and to include team channel sites in the list
$m365Sites | ForEach-Object {
# Connect to SharePoint site
Connect-PnPOnline -Url $_.Url -Interactive
#Request Reindex
Request-PnPReIndexWeb
Write-host "Reindexing: " $_.Url
}
# Disconnect SharePoint online connection
Disconnect-PnPOnline
Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell
The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?
Contributors
Author(s) |
---|
Reshmee Auckloo (script) |
Mikael Svenson (caution text) |
Ganesh Sanap (script) |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.