Recreate a Solr Docker Image for Sitecore xDB

Throw away your Sitecore Solr images and recreate them from scratch. Re-apply needed Sitecore customizations to the schemas and reindex all data, including the ones within xDB cores.

Recreate a Solr Docker Image for Sitecore xDB

As I've refreshed my Docker Desktop installation, I needed to re-create a few Docker images I use in my current Sitecore projects. As a developer usually you have some docker-compose files and/or scripts to create all your needed resources at any time. So do I.
Sounds like an easy task these scripts this in place: Just fire them up, get a coffee and start working with a fresh Sitecore install!

Preparing a Linux-based Solr Image

Getting the new image indeed is no problem (I usually use a Solr Alpine image). But now that we have a fresh image, we're missing all the data.

Working with Sitecore I'm used to put the Solr search service into a Docker container, so there are a few additional things that must be prepared in order to use the image with Sitecore:

  • the Sitecore Solr schemas must be deployed
  • the Solr index data must be re-built

For most indexes, this can be accomplished by populating the Solr schemas from the control panel and then let all the indexes rebuild. Depending on the size of the content database this may take some time.

What about xDB Indexes

For xDB indexes however there is no GUI to handle this just as easy. Luckily Sitecore provides still enough capabilities to also do the job here. It is actually documented quite in detail in the Sitecore documentation. However, a few prerequisites must be fulfilled to perform the rebuild correctly:

  1. You must have a rebuild core. Most probably this is already contained in your Solr image, as Sitecore requires it for the initial installation anyway.
  2. The xDB cores need to have the correct schema.

So how to apply the schema changes needed for the xDB calls?

Again Sitecore provides all the required things to make this happen. During the initial installation of Sitecore it's handled as part of the SIF based installation process. And for sure, we can make it our deal, to just execute this one tiny but so important function to us without a complete Sitecore installation again!

Make sure you have your SIF module in the global PowerShell modules folder or load it:

// Import the SIF Module
Import-Module <path-to-your-SIF-module>

To apply the schema changes we can now execute the SIF commandlet

// Apply solr schema
Invoke-ManageSolrSchemaTask -Address "<local-solr-https-uri>" -Core "sitecore_xdb" -ArgumentsFile "<path-to-your-xconnect-website>App_Data\solrcommands\schema.json" -Verbose
Invoke-ManageSolrSchemaTask -Address "<local-solr-https-uri>" -Core "sitecore_xdb_rebuild" -ArgumentsFile "<path-to-your-xconnect-website>\App_Data\solrcommands\schema.json" -Verbose

Once the schema has been applied correctly, we can follow the guide of Sitecore  is to get the index data back:

// Reindex xDB core
<path-to-your-xconnect-website>\App_Data\jobs\continuous\IndexWorker\XConnectSearchIndexer.exe -requestrebuild

Alternatively (or if IndexWorker is not available to you because of distributed environments) there is a way to force the rebuild by posting an index document directly to the solr xdb core:

// Reindex xDB Core
Invoke-WebRequest <local-solr-https-uri> -Method Post -Body '{"id":"xdb-rebuild-status", "lastupdated_dt":"2017-05-24T10:15:47.603436Z", "rebuildstate_l":1, "progresstotal_d":0.0, "progresscurrent_d":0.0}'

After a few minutes indexing of the xDB core is finished, and you can re-find all you indexed based datas such as contacts within Sitecore Marketing functionalities.