【问题标题】:Azure Search: Indexed document count does not match the total number of uploaded recordsAzure 搜索:索引文档计数与上传记录的总数不匹配
【发布时间】:2020-06-02 19:36:13
【问题描述】:

我一直在尝试使用 Azure Search .NET SDK 将 31 条不同的记录从 SQL 服务器上传到 Azure 云。我能够上传记录而不会出现任何技术错误。甚至日志都通过将所有 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; }
}

【问题讨论】:

  • 您检查所有记录是否唯一?

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


【解决方案1】:

这可能是因为您发送了重复的数据,如果您想检查,请添加此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 server中更新或创建的实际结果。

【讨论】:

  • 谢谢@jishan siddique。这行代码字符串 json = Newtonsoft.Json.JsonConvert.SerializeObject(data);帮助我找出在我不知情的情况下生成的重复密钥。因此它们被过滤掉了。
  • 欢迎,兄弟 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多