Best way to delete/manage custom indexed objects


We have some custom object in our index, for example contact persons that does not have any EpiServer page. We index them with a schedule job that updates the index and that is working great but I can't get a good delete-part to work.

I wan't to do something like this

List<string> Ids = existingIds;
client.Delete<ContactPerson>(x=> !ids.Contains(x.Id))
But I can't use Contains and when I try with Match
client.Delete<ContactPerson>(x=> !ids.Match(x.Id))
It says that i can't compare.

I got it to work by do a search for all ContactPersons like this

public void DeleteExtraContats(List<string> ids)
var client = Client.CreateFromConfig();
var result = client.Search<ContactPersonToIndex>().Take(0).GetResult().TotalMatching;
var items = client.Search<ContactPersonToIndex>().Skip(0).Take(result).GetResult();

foreach (var item in items.Where(item => !ids.Contains(item.Id)))


But it does not feel efficient and there must be a better way to do it.

Sep 17, 2013 9:18

For checking if a value is in a list you have to use "In" (this will return an appropriate filter):

client.Delete<ContactPerson>(x => !x.Id.In(ids))


Best Regards,


Sep 17, 2013 9:48

So simple when you know what to do ;-) Thanks Henrik, it's working great!

Sep 17, 2013 10:11
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.