We have a Sitecore 8.1-3 instance. Previously we had used the user's Sitecore username as the identifier in xDB. Then after the site was live for some time we realized that using the user's email address was a much better solution. So we changed the site to use email address in the Identify method. And the site has been running for a while with that.
However this caused the unfortunate situation where we have some users that have two contacts in xDB - one identified by their Sitecore username and one identified by their email address.
Is there any way that I can write a script that would merge these? Ultimately what I would like to do is look for all of the contacts that are identified by their Sitecore username (OLD contact), then for each one of those go find their contact that is identified by their email address (NEW contact). I would like to then transfer all of the Sitecore analytics activity from the OLD contact to the NEW contact. Then delete the OLD contact. Is this even possible?
Right now the problem we have is that when you search in Experience Profile you get double results for some contacts. And some of the activity is assigned to one contact and some is assigned to the other contact. We would like to find a way to clean this up. Any ideas?