
Here are some solutions for you to meet your needs.
1) To use Search and Offline Availability Setting:
*Go to the subsite to be excluded from the search result;
*Click on "Search and offline availability" under Search group in Site settings page;
*Choose "No" for Allow this site to appear in search results option;
*Click on "OK" to save your changes.
2) To use PowellShell:
#Load SharePoint Online Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Variables for Processing
$SiteUrl = "https://XXXXX.sharepoint.com/sites/XXXXX"
#Get Credentials to connect
$Cred= Get-Credential
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the Web
$Web = $Ctx.Web
$Ctx.Load($Web)
$Ctx.ExecuteQuery()
If($Web.NoCrawl)
{
Write-host -f Yellow "Site is Already excluded from Search Index!"
}
Else
{
#Exclude Site from Search
$Web.NoCrawl = $True
$Web.Update()
$Ctx.ExecuteQuery()
Write-host -f Green "Site is Excluded from Search Index Successfully!"
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
We can also use PnP PowerShell to exclude a site from SharePoint Online search index:
#Parameter
$SiteURL= "https://XXXXX.sharepoint.com/sites/XXXXX"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Exclude Root Web of the Site Collection from Search Index
$Web = Get-PnPWeb
$Web.NoCrawl = $true
$Web.Update()
Invoke-PnPQuery
Note: Please update the variable $SiteURL with your SharePoint Online environment(the subsite to be excluded from the search result).
3) To use Query Rules:
*Navigate to your search center;
*Go to Search Results page by entering some search query and clicking on search;
*Once You are in Search results page (Pages/results.aspx), Click on Settings gear >> choose "Edit Page";
*Locate "Search Results" web part, and choose "Edit this web part" from its context menu. This opens the web part properties pane;
*In the Web part properties panel, Click on "Change Query" button. You'll get a Popup page to build your query;
*In the "Build your query" dialogue window, select "Path" in the property filter dropdown. Change the parameter to "Not starts with". For the value, select "Manual value" and then type the URL for the site you want to exclude and then click the button "Add property filter". This appends the "Query Text" box with “-Path:https://site-to-remove/”.
Save, Check-In and Publish the page! If you want to exclude multiple subsites, use OR operator. E.g. {searchboxquery} -Path:https://XXXXX.sharepoint.com/sites/XXXX1 OR -Path:https://XXXXX.sharepoint.com/sites/XXXX2.
4) To use Remove Search Results:
Go to search administration in SharePoint admin center -> Remove Search Results:
Type the subsite URL you want to exclude from search results into text box -> Remove Now:
This method may take some time to work, please be patient for a while.
I hope this information has been useful, please let me know if you still need assistance.
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.