【发布时间】:2020-12-02 02:49:35
【问题描述】:
我需要添加带有子项的新文档或将子项添加到现有的父项。 我知道该怎么做的唯一方法是丑陋的:
public async Task AddOrUpdateCase(params)
{
try
{
await UpdateCase(params);
}
catch (RequestFailedException ex)
{
if (ex.Status != (int)HttpStatusCode.NotFound)
throw;
await AddCase(params);
}
}
private async Task UpdateCase(params)
{
// this line throws when document is not found
var caseResponse = await searchClient.GetDocumentAsync<Case>(params.CaseId)
// need to add to existing collection
caseResponse.Value.Children.Add(params.child);
}
我认为如果这个文档不包含集合不会有任何问题。如果有子集合,则不能使用 MergeOrUpload。您需要从索引加载它们并添加元素。
有没有更好的办法?
【问题讨论】:
标签: azure azure-cognitive-search azure-search-.net-sdk