Customize Solr Managed Schema in Sitecore 9+

In Sitecore 9+ we can now populate Solr managed schema through the Sitecore control panel. It is still possible to use the legacy schema.xml files, but it is actually a lot more comfortable to be able to just deploy the schema with one click.

Sitecore currently has some basic schema which it populates and has created the contentSearch.PopulateSolrSchema pipeline as extension point. Mikael Högberg has written a post describing this extension point and I’ve built the following simple processor based on that. It reads Managed Schema update commands as XML and applies them to the indexes you have specified (pipe-separated)

Feel free to use and extend it.

Caveat: Solr only accepts the add-field-type command if the field is not contained in the managed schema yet. The replace-field-type will only work if it is already there. This is a bit annoying and could be worked around by checking if the field exists in the schema in code and then changing add to replace and vice versa.

Also, the schema update will fail silently if there are any errors in the update commands. I’ve found it helpful to first test the update commands as JSON against Solr’s API directly and then convert that JSON to XML.

Update 05.11.2018:
Added a add-or-replace-field-type command which is automatically replaced to “add-field-type” or “replace-field-type” depending if the field type already exists in the schema.

One response to “Customize Solr Managed Schema in Sitecore 9+”

Leave a Reply

Your email address will not be published. Required fields are marked *