Wednesday, November 9, 2016

Zapping Solr Cores with Powershell

Imagine you've been working on a feature that creates Sitecore Solr indexes with SIM. Three's a lot of testing that goes into that.
Suppose I tweak this? Does it still work? And each go round creates another 15 indexes. You end up with a lot of indexes named "test1a_sitecore_core_index, test1a_sitecore_master_index" and so forth. I think I was up above 200 of these at some point. SIM has a bulk delete feature but it doesn't (yet) support deleting Solr indexes, so I did a little googling into Powershell to see if I could whip up a script to do some house cleaning (True confession, I waited until Solr was DYING.). Here's what I came up with:



Here's what the script does.

  • Loads a required parameter "-prefix".  This is useful since SIM creates Solr cores with the instance name of the site.
  • Creates an instance of the WebClient class, which we will use to communicate to the Solr API.
  • Loads the results of "/solr/admin/cores" to an XmlDocument object. The [xml] prefix causes the string return value to be loaded to an XmlDocument instance.

No comments:

Post a Comment