There’s been an interesting question around how to rebuild the sitecore_analytics_index but specifically only for contact data.
As you’ve probably know that sitecore_analytics_index is not available to be indexed manually – go to the indexing manager in the control panel if you want to check. This is because the index is configured using an observer crawlers.
However there are ways to manually rebuild the sitecore_analytics_index. The example given in that seems to be specifically about rebuilding the interactions documents while what we want is to build the contacts.
I gained some hints from the provided example though, let’s have a look at the following code.
1 2 3 4 5 6 7 8 9 10 11 |
ContentSearchManager.GetIndex("sitecore_analytics_index").Reset(); var poolPath = "aggregationProcessing/processingPools/live"; var pool = Factory.CreateObject(poolPath, true) as ProcessingPool; var driver = MongoDbDriver.FromConnectionString("analytics"); var visitorData = driver.Interactions.FindAllAs<VisitData>(); var keys = visitorData.Select(data => new InteractionKey(data.ContactId, data.InteractionId)); foreach(var key in keys) { var poolItem = new ProcessingPoolItem(key.ToByteArray()); pool.Add(poolItem); } |
In particular this line
1 |
var poolPath = "aggregationProcessing/processingPools/live"; |
I then go to the handy showconfig.aspx page to find the following
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<processingPools> <live type="Sitecore.Analytics.Data.MongoDb.ProcessingPool.MongoDbProcessingPool, Sitecore.Analytics.MongoDb" singleInstance="true"> <param desc="connectionStringName"> tracking.live</param> <Name>live</Name> <Enabled>true</Enabled> <MaxItemErrorCount ref="aggregationProcessing/maxItemErrorCount"/> </live> <history type="Sitecore.Analytics.Data.MongoDb.ProcessingPool.MongoDbProcessingPool, Sitecore.Analytics.MongoDb" singleInstance="true"> <param desc="connectionStringName"> tracking.history</param> <Name>history</Name> <Enabled>true</Enabled> <MaxItemErrorCount ref="aggregationProcessing/maxItemErrorCount"/> </history> <contact type="Sitecore.Analytics.Data.MongoDb.ProcessingPool.MongoDbProcessingPool, Sitecore.Analytics.MongoDb" singleInstance="true"> <param desc="connectionStringName"> tracking.contact</param> <DuplicateKeyStrategy>AllowAndMerge</DuplicateKeyStrategy> <Name>contact</Name> <Enabled>true</Enabled> <MaxItemErrorCount ref="aggregationProcessing/maxItemErrorCount"/> </contact> <pathAnalyzerLive type="Sitecore.PathAnalyzer.Processing.ProcessingPool, Sitecore.PathAnalyzer" singleInstance="true" patch:source="Sitecore.PathAnalyzer.Processing.config"> <param desc="connectionStringName"> tracking.live</param> <param desc="collectionName"> PathAnalyzerProcessingPool</param> <DuplicateKeyStrategy>AllowAndMerge</DuplicateKeyStrategy> <Name>trees</Name> <Enabled>true</Enabled> </pathAnalyzerLive> <pathAnalyzerHistory type="Sitecore.PathAnalyzer.Processing.ProcessingPool, Sitecore.PathAnalyzer" singleInstance="true" patch:source="Sitecore.PathAnalyzer.Processing.config"> <param desc="connectionStringName"> tracking.history</param> <param desc="collectionName"> PathAnalyzerProcessingPool</param> <DuplicateKeyStrategy>AllowAndMerge</DuplicateKeyStrategy> <Name>trees</Name> <Enabled>true</Enabled> </pathAnalyzerHistory> </processingPools> |
Which shows the processingPools configured for the aggregation processes. From there I can spot the contact element definition which seems to be the one that I’m looking for and start building the code for it.
result:
1 2 3 4 5 6 7 8 9 10 11 |
ContentSearchManager.GetIndex("sitecore_analytics_index").Reset(); var poolPath = "aggregationProcessing/processingPools/contact"; var pool = Factory.CreateObject(poolPath, true) as ProcessingPool; var driver = MongoDbDriver.FromConnectionString("analytics"); var contacts = driver.GetCollection("Contacts").FindAll().SetFields(new string[] {"_id"}); foreach(var contact in contacts) { var contactId = contact[0].AsGuid; var poolItem = new ProcessingPoolItem(contactId.ToByteArray()); pool.Add(poolItem); } |
Depending on your needs, you might want to only reindex known contacts for example. You can take the above example and adjust it yourself.
Does this code work on sitecore 8.2? I cannot make that work for driver.GetCollection(“Contacts”)—-cant find suitable class to do. Can you please add namespaces for doing this?
I can’t recall the namespace but if you do a quick google search on the MongoDbDriver class you should be able to figure it out eventually 🙂