Duplicate entries in custom index on incremental update

I’ve had a problem with a custom index some time ago. Entries were showing up multiple times when doing incremental updates of the index i.E. when saving an item. The only thing that would clean up the index again would be a full index rebuild.

The reason for this happening was, on incremental updates, Sitecore would add a new document to the index and leave the old one untouched thus duplicating the entry. The default indexes (core,master,web) would not show the same behaviour which made me check each and every field of the default fieldMap configuration… and voilà: The _uniqueid field needs to be converted to lowercase in order to be matched correctly. (GUIDs are saved as lowercase in lucene but are uppercase in .NET) To resolve the issue, all I needed to do is add the _uniqueid field to the fieldNames configuration as follows:

I also added the _template field to ensure filtering by template ID works correctly. You generally need to do this with every GUID field you’re querying.

Unfortunately, there are still several custom index tutorials out there which don’t take this into account. If you’re looking for a clean template to start a new custom index, check out Mikkel’s post.

Leave a Reply

Your email address will not be published. Required fields are marked *