【问题标题】:How to delete a document (table) or a group of documents using Azure Search SDK (Library)如何使用 Azure 搜索 SDK(库)删除一个文档(表)或一组文档
【发布时间】:2020-07-13 03:57:12
【问题描述】:

我想使用库 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
                }
            });
        }

【问题讨论】:

    标签: c# azure-cognitive-search azure-search-.net-sdk


    【解决方案1】:

    我发现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
                }
            });
        }
    

    【讨论】:

      猜你喜欢
      • 2023-01-05
      • 1970-01-01
      • 1970-01-01
      • 2016-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多