如何使用 Azure 搜索 SDK(库)删除一个文档 (table) 或一组文档

How to delete a document (table) or a group of documents using Azure Search SDK (Library)

我想使用库 Microsoft.Azure.Search 使用文档 ID 删除项目(文档)。我该怎么做?

遵循我目前的尝试:

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
                }
            });
        }

我发现 this git post 我适应了我的情况。最终结果听起来像这样:

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
            }
        });
    }