Recently, I had to update the search schema for a site collection between multiple SharePoint Online environments (i.e. DEV to QA and so on). The update was pretty simple: replace a crawl property setting and an alias by an other for a couple of managed properties in the schema. Since I could do it manually, the whole solution deployment was fully automated so I had to find a way to update the search schema without recreating the site collection from scratch. This is likely the case when your work on a development project where you can’t remove the production environment site collection and have to handle incremental updates.
Basically, the original search configuration to update was:
…and the desired configuration was:
For those who don’t know, SharePoint provides an OOTB import/export feature available in the site settings. It allows to reuse, as an XML file, a search configuration from a site/site collection (or globally) to an other including managed properties, result sources, query rules and so on.
SharePoint import/export default behavior
I first used this feature by importing the exported XML to my target site collection without any modification with the following result:
Hmm, not really what I wanted. By default, crawled property mappings and aliases are simply concatenated. To be able to reset these values with the new settings, you will need to tweak the XML file a little bit.
Reset a search managed property
To reset specific managed properties, you will to perform the following steps:
- In an other site collection similar to the target one (i.e DEV in you want to update QA), update your search schema via the UI
- Export the configuration as XML
- Format the XML file to a more readable format, for instance using this tool: https://www.freeformatter.com/xml-formatter.html
- Update the file as follow:
- Update these values to « false«
- Save your file and make sure the encoding is « UTF-8 »
At this step, if you import the modified file as is to your target site collection, you will observe the following behavior:
Crawled properties will be set correctly but aliases will still be concatenated.
To completely remove the previous schema configuration, the solution is to update your previous schema by moving your new properties to other free slots (if you used the placeholder ones like « RefinableStringXXX« ). SharePoint lets you to use a large range of slots so it wouldn’t be a problem. Also don’t forget to « reset » the previous ones by setting blank values.
- Export your search configuration again. By this way, you will be able to catch deletions overrides in the output XML. You can find them easily by searching for the « ManagedPid » in the file. If there is no matches in the <Mappings> XML section, it means this is a deletion.
- Set the AliasesOverridden and MappingsOverridden property values to « false » for those managed properties (you can keep new ones untouched).
- Import this new file to your target site collection to reset previous properties and view the new ones as expected. That’s it!
I hope this little trick could help for your automated deployments!