gpt4 book ai didi

c# - .Net Core Azure认知搜索删除文档

转载 作者:行者123 更新时间:2023-12-02 08:16:12 24 4
gpt4 key购买 nike

我在 .Net Core 3.1 应用程序中使用 Azure.Search.Documents 包来实现 azure 认知搜索。我有一个要求,我必须从文档中删除现有数据。我通过引用文档尝试了几种方法,但没有一个起作用。

我尝试过以下方法

方法1

var searchIndexClient = new SearchIndexClient(new Uri(<URI>), new AzureKeyCredential("XYZ"));

var searchClient = searchIndexClient.GetSearchClient(indexName);
var options = new IndexDocumentsOptions { ThrowOnAnyError = true };
var res = await searchClient.DeleteDocumentsAsync("Id", new List<string> { "1", "2", "3"}, options);

方法 2:

var searchIndexClient = new SearchIndexClient(new Uri(<URI>), new AzureKeyCredential("XYZ"));

var searchClient = searchIndexClient.GetSearchClient(indexName);

var batch = IndexDocumentsBatch.Delete("Id", documents);

var options = new IndexDocumentsOptions { ThrowOnAnyError = true };
var res = await searchClient.IndexDocumentsAsync(batch, options);

当我尝试这些方法时,出现以下错误:

{
"error": {
"code": "MissingRequiredParameter",
"message": "The request is invalid. Details: actions : No indexing actions found in the request. Please include between 1 and 32000 indexing actions in your request.",
"details": [{
"code": "MissingIndexDocumentsActions",
"message": "No indexing actions found in the request. Please include between 1 and 32000 indexing actions in your request. Parameters: actions"
}
]
}
}

感谢任何帮助,注意:我只想使用 SDK 来完成此操作,而不是使用 Rest API

最佳答案

DeleteDocumentsAsync会删除一个完整的文档或者批量删除一个文档。 IndexDocumentsBatch.Delete会根据索引中的key或者字符串值批量删除文档。

这些方法都不会删除文档字段值,只会删除完整文档。如果您需要从文档中删除现有字段,请考虑 IndexDocumentsAction.Merge并确保您要删除的字段为空,以便合并在所需字段中添加空值,并保留其余字段不变。

更多信息请点击:https://learn.microsoft.com/azure/search/search-howto-dotnet-sdk

关于c# - .Net Core Azure认知搜索删除文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73453435/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com