Duplicate entries in custom index with syncMaster strategy

Search for a command to run...

No comments yet. Be the first to comment.
Polly is great library for easily configuring different kinds of policies around code execution, be it retry, circuit breaker, caching or lots of other things. It's probably most often used around HTTP requests. If you haven't heard about it you defi...

This is part 2 of my series on unit testing in .NET (C#) and will be about my conventions regarding naming unit tests, how to structure them and which parts to test. And lastly I will help you increase readability of assertions and potential error me...

I feel like unit testing is very important and very beneficial in a lot of ways. It helps with not breaking existing functionality and thereby also making you more confident in changing code without fear of breaking important stuff. Often it also mak...

I've been working with Swagger through NSwag a lot recently and also needed to get it to work when hidden behind a reverse proxy - i.e. another service forwarding a request to the service exposing the Swagger UI. Some of the issues I've had along the...

The other day I was writing a unit test to verify what was supposed to happen when a Task would throw an exception when awaited. It wasn't as straight forward as I first assumed, but I quickly found this Stack Overflow post that helped me: https://st...

If you have tried creating your own custom index with Sitecore 7 you might have run into this issue already. We ran into this issue at work yesterday.
After saving an item it would create another entry in our custom index with the new data but the old entry would still be there. Another entry would be added after each save. After rebuilding the index everything would be fine but that wasn’t really a solution.
A quick google search revealed the cause of our problem. This appears to only be a problem when using the syncMaster update strategy (which updates the index whenever an item is saved in the master database – in contrast to onPublishEndAsync which only updates after a publish).
If you are missing the _uniqueid field in your index configuration, Lucene won’t be able to identify the updated item in the index and instead creates a new entry.
Adding that field to your field names list in your index configuration as shown below should fix the problem.
<fieldNames hint="raw:AddFieldByFieldName">
<!-- Use <fieldType> instead of <field> if you are using Sitecore 7.0 rev130424 (Initial) -->
<field fieldName="_uniqueid"
storageType="YES"
indexType="TOKENIZED"
vectorType="NO"
boost="1f"
type="System.String"
settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration,
Sitecore.ContentSearch.LuceneProvider">
<analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer,
Sitecore.ContentSearch.LuceneProvider" />
</field>
</fieldNames>
As noted in the comment, if you are using the initial release of Sitecore 7.0 (rev130424) the field element should be named <fieldType> instead of <field> as this was changed in Sitecore 7.0 Update 1 (rev130810).
So, if you are making your own custom index remember to add this field to your index configuration.