Reputation: 16256
I want to delete an item (document) using the document Id using the library Microsoft.Azure.Search
. How can I do that?
Follows what I've tried so far:
public Task DeleteItems(IEnumerable<string> itemsIds)
{
return Task.Run(() =>
{
IndexBatch<string> batch = IndexBatch.Delete<string>(itemsIds);
try
{
//Gets the search service and add the delete batch to be perfomed on the Index
this.GetSearchServiceIndex().Documents.Index(batch);
}
catch (IndexBatchException ex)
{
//Do something in here
}
});
}
Upvotes: 1
Views: 609
Reputation: 16256
I found out this git post I adapted to my case. The final result sounds like this:
public Task DeleteItems(IEnumerable<string> itemsIds)
{
return Task.Run(() =>
{
IndexBatch batch = IndexBatch.Delete("id", itemsIds);
try
{
//Gets the search service and add the delete batch to be perfomed on the Index
this.GetSearchServiceIndex().Documents.Index(batch);
}
catch (IndexBatchException ex)
{
//Do Someting here
}
});
}
Upvotes: 1