I have a working custom index configured, it includes some custom fields and has specifically included fields and templates to keep it light. It uses the default SitecoreItemCrawler. I'm on 10.1 deployed on Azure.
I just want to run an update on a specific document in my index, to force some computed fields to be recomputed and persisted in the Solr index.
I'm struggling to get IndexCustodian to perform the update, here is relevant code:
using (var solr = ContentSearchManager.GetIndex("my_site_search"))
{
// just for example, this comes from elsewhere
string exItemUri = "sitecore://web/{d1adabf3-393e-4d59-b9e3-a3104253b879}?lang=en&ver=1";
var ctx = solr.CreateSearchContext(Sitecore.ContentSearch.Security.SearchSecurityOptions.DisableSecurityCheck);
using (new SecurityDisabler())
{
Log.Info($"Context User: {Sitecore.Context.User.Name}", "SU");
var indexableUniqueIds = new[] { new SitecoreItemUniqueId(exItemUri) };
var db = Factory.GetDatabase("web");
var it = db.GetItem(new DataUri(exItemUri));
var tempItem = (SitecoreIndexableItem)it;
// ** THIS DOES NOT WORK #1
// solr.Refresh(tempItem); This also doesnt work - noted comment that this should not be done, IndexCustodian should be used
var job = IndexCustodian.Refresh(solr, tempItem);
//job.Start(); // doesn't make any difference - job is started anyway by IndexCustodian(?)
job.Wait();
Log.Info("Ran Refresh: indexUniqueIds: " + indexableUniqueIds[0].ToString(), "SU");
// ** THIS WORKS, BUT I'M NOT USING THE INDEXCUSTODIAN #2
using (var upctx = solr.CreateUpdateContext())
{
solr.Operations.Update(tempItem, upctx, solr.Configuration);
upctx.Commit();
}
Log.Info("Ran Update indexUniqueIds: " + indexableUniqueIds[0].ToString(), "SU");
}
}
I've tried various methods on IndexCustodian (.Update, .Refresh, .ForcedIncrementalUpdate etc), but all have the same effect - I see the job going into the jobs queue, it gets processed, however does nothing to my index - it also states 0 items updated. I'm examining index with the Solr query tool.
I've run out of things to try - I'm not sure if approach #2 is correct as I believe we are supposed to use the IndexCustodian.
Any help greatly appreciated!