1

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
                }
            });
        }
Ricardo Rocha
  • 14,612
  • 20
  • 74
  • 130

1 Answers1

1

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
            }
        });
    }
Ricardo Rocha
  • 14,612
  • 20
  • 74
  • 130