Compare Sitecore Vs Solr Items

Have you ever faced any urgent Production issue where your deployment succeeded and site is working fine and then you come to know that the number of items in the Solr and Sitecore don’t match and you also want to see the delta of those differences. You can also use this information to setup a threshold to setup alerts if the mismatch of items surpasses a defined limit(I used Amazon’s SNS(Simple Notification Service) to notify via email and text to the Production SWAT team as soon as threshold passed the limit)

This Powershell script will be very handy for you. The base idea is that you get detaisl of items from your Sitecore master and web database and also Solr master and web databases. Once you have these JSONs in hand comparing those objects would not be that difficult. Just filter out the columns you need and you are good to go.

//First Get Items From Sitecore Master Database
$childsMaster = Get-ChildItem master:/sitecore/content/../Products -Language * -Version *
write-host “Count of items Product Catalog(Master): ” $childsMaster.length

//Then Get Items From Sitecore Web Database
$childsWeb = Get-ChildItem web:/sitecore/content/../Products -Language * -Version *
write-host “Count of items Product Catalog(Web): ” $childsWeb.length

//Then Get Items From Sitecore Solr Master
$items_catalog_index_master = wget “*&fq=_language%3Aen-CA&rows=9999&fl=marketsku_s&wt=json&indent=true” | ConvertFrom-Json
write-host “Count of items catalog_index_master: ” $items_catalog_index_master.response.numfound

//Then Get Items From Sitecore Solr Slave
$items_catalog_index_web = wget “*&fq=_language%3Aen-CA&rows=9999&fl=marketsku_s&wt=json&indent=true” | ConvertFrom-Json

write-host “Count of items catalog_index_web: ” $items_catalog_index_web.response.numfound

write-host “Compare Sitecore Master Vs Web Databases”

Compare-Object $childsMaster $childsWeb -PassThru
write-host “Compare Sitecore Solr catalog_index_master Vs catalog_index_web”

Compare-Object ($ ($

write-host “Compare Master Database Vs Solr catalog_index_web”
Compare-Object ($childsMaster.comparefieldname) ($ -PassThru