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))) { client.Delete<ContactPersonToIndex>(item.Id); }
}
But it does not feel efficient and there must be a better way to do it.
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)))
{
client.Delete<ContactPersonToIndex>(item.Id);
}
}
But it does not feel efficient and there must be a better way to do it.