Remove specific object types from Episerver find

Vote:
 

Hello

I'm currently indexing a custom object in my episerver find instance which looks like this:

var myObject = new MyCustomObject
{
    MyCustomFieldOne = "foo",
    MyCustomFieldTwo = "bar"
};

searchClient.Index(myObject);

My question is, what's the most efficient way to then programtically delete all instances of this object in the find index later, as a bulk operation?

#268332
Dec 13, 2021 19:00
Vote:
 
#268335
Dec 13, 2021 22:11
Vote:
 

Problem with the Delete() method though is that it requires an Id parameter.

So to achieve that I'd need to write a query that gets all of the Find Ids of MyCustomObject, and then deletes them one-by-one.

I was wondering if there was a more efficient way to do this as a bulk operation. It would be tricky for me to retreieve all of the ids of MyCustomObject, as there are > 1000 instances (and Find only returns 1000 results at a time, max).

#268382
Dec 14, 2021 10:02
Scott Reed - Dec 14, 2021 15:03
There's multiple method, you can just writing a matching criteria such as the second example in the posted link. So just write a lambda that always matches true like where ID > 0 or something
Vote:
 

Hi FalconX,

Why can't you use the built in UI to clear the index and then perform and re-index?

Thanks

Paul

#268387
Dec 14, 2021 14:27
Mari Jørgensen - Dec 20, 2021 7:33
It might not be an option since he is indexing custom objects.
Vote:
 

Easiest way is to do as Scott suggested, to remove items using query:

client.Delete<MyCustomObject>(x => x.Id.Exists());
#268695
Dec 20, 2021 7:35
Scott Reed - Dec 20, 2021 9:42
Thanks Mari, exactly!!
FalconX - Dec 20, 2021 10:15
Ah yes, so simple, thank you!! :D
* 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.