SharePoint is a web portal which acts as a collaborative platform to manage, search, and share contents. SharePoint search is an excellent and highly powerful search. Search schemas can be configured and managed in SharePoint to make it more efficient based on our needs. We can create search properties through this search schema and map it to a list column or an existing user profile property. Those contents will be crawled and will be available for the user search. SharePoint on-premise has the option to crawl the properties and contents manually or automatically. But in SharePoint online, it has to be performed automatically. So, we need to wait for an hour or two to make content available for search, after adding it. In case we need to perform a search crawl manually, we can always contact Office 365 support team.
Create a Search Property:
First, we need to know how to create a search property before migrating it.
- We should log into the SharePoint Admin Center.
- Click Search from the left menu.
- Select “Manage Search Schema”
- Select “New Managed Property”
- Then give the Property Name, Description, Type of the property and select the Searchable, Retrievable checkbox.
- In the mapping to crawled property section, select “Add a Mapping” to choose the property or column which should be included inside the search. Then, select Ok to create it.
Migrating Search Crawl Property:
After creating the property, create a windows application and add “Microsoft.SharePointOnline.CSOM” Nuget package to the solution. We have to perform Export and Import operation to perform the migration. For exporting the search managed property use the below code snippet.
- private static string exportSearchSettings(ClientContext clientContext) {
- SearchConfigurationPortability searchConfiguration = null;
- SearchObjectOwner searchObjectOwner = null;
- ClientResult < string > configResults = null;
- string stringresult = string.Empty;
- try {
- searchConfiguration = new SearchConfigurationPortability(clientContext);
- searchObjectOwner = new SearchObjectOwner(clientContext, SearchObjectLevel.SPSiteSubscription);
- configResults = searchConfiguration.ExportSearchConfiguration(searchObjectOwner);
- clientContext.ExecuteQuery();
- if (configResults.Value != null) stringresult = configResults.Value;
- } catch (Exception) {
- throw;
- }
- return stringresult;
- }
From the above code, we will be getting an xml string which can be imported to another site. After the above code execution, make sure that you’re storing the content somewhere to reuse it. I am saving the document as a file inside the application as “searchConfiguration.xml”
After storing it, use the below code to migrate the configurations to a new tenant.
- private static void importSearchSettings(ClientContext clientContext) {
- SearchConfigurationPortability searchConfiguration = null;
- SearchObjectOwner searchObjectOwner = null;
- string location = string.Empty, directory = string.Empty;
- try {
- location = Assembly.GetExecutingAssembly().Location;
- directory = Path.GetDirectoryName(location);
- searchConfigurationString = System.IO.File.ReadAllText(directory + "/searchConfiguration.xml");
- searchConfiguration = new SearchConfigurationPortability(clientContext);
- searchObjectOwner = new SearchObjectOwner(clientContext, SearchObjectLevel.SPSiteSubscription);
- searchConfiguration.ImportSearchConfiguration(searchObjectOwner, searchConfigurationString);
- clientContext.ExecuteQuery();
- } catch (Exception) {
- throw;
- }
- }
I hope you learned how to migrate search properties from one tenant to another. Feel free to fill my comment box with your thoughts and doubts on this article.
Happy SharePointing!!!