c# - Azure 搜索:索引文档计数与上传记录的总数不匹配
问题描述
我一直在尝试使用 Azure Search .NET SDK 将 31 条不同的记录从 SQL 服务器上传到天蓝色的云。我能够上传记录而不会出现任何技术错误。甚至日志也通过将所有 31 条记录的状态代码返回为 200 来确认所有 31 条记录都被索引了
然而,在 azure 门户中,当我看到索引上的文档计数时,我只看到 27 个。这意味着由于某种原因,4 条记录没有被索引。如果两条记录具有相同的派对 ID,则只有一条记录被上传。为了避免这种情况,我在 dto 中创建了一个新键,它是派对 ID 和标签 ID 的组合,以确保每一行的键都是唯一的。然而,这并没有帮助,我不断丢失具有重复 partyId 的行。
有人可以向我解释为什么记录丢失了吗?我尝试用谷歌搜索相关文章,但到目前为止没有运气。
下面是对象 Dto
public class PartyTagMappingDto
{
[Key] //combination of partyId and TagId
public string Id { get; set; }
[IsFilterable,IsSearchable]
public string PartyId { get; set; }
[IsSearchable,IsFilterable]
public string TagId { get; set; }
[IsSearchable,IsFilterable]
public string TagName { get; set; }
public string Description { get; set; }
}
解决方案
也许这有可能您正在发送重复的数据,如果您想检查请添加这个code
您可以找到您的4
记录的去向。
var batch = IndexBatch.New(actions);
try
{
var data = GetIndexClient(IndexName).Documents.Index(batch);
var passResultCount = data.Results.Where(x => x.Succeeded).Count();
var failResultCount = data.Results.Where(x => x.Succeeded==false).Count();
var MessageResult = data.Results.Where(x => !string.IsNullOrEmpty(x.ErrorMessage));
var keyResult = data.Results.Where(x => !string.IsNullOrEmpty(x.Key)).Select(x=>x.Key).ToList();
var unikKey = keyResult.Distinct().ToList();
string json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
}
catch (IndexBatchException e)
{
// Sometimes when your Search service is under load, indexing will fail for some of the documents in
// the batch. Depending on your application, you can take compensating actions like delaying and
// retrying. For this simple demo, we just log the failed document keys and continue.
Console.WriteLine(
"Failed to index some of the documents: {0}",
String.Join(", ", e.IndexingResults.Where(r => !r.Succeeded).Select(r => r.Key)));
}
注意:在unikKey
结果中可以找出在 azure 服务器中更新或创建的实际结果。
推荐阅读
- excel - 通过 Windows 调度程序调度启用宏的 Excel 工作表
- spring-boot - JPA Hibernate - 如何(REST api)使用外键作为ID发布对象?
- jquery - jQuery触发嵌套表单rails cocoon上的所有实例
- python - Django ModelForm 未提交
- php - php tree 获取子节点所有父节点的列表
- angular - Angular slickgrid 列删除排序选项无法正常工作
- android - 数据绑定监听器
- c# - Xamarin.Forms StackLayout 与 x:Name 在 DataTemplate 中时找不到
- c++ - 具有 2 个分量数组的特征映射到 3 个向量
- r - #R #二元运算符的非数字参数 #xts 对象 * 整数