Search code examples
c#.netazureazure-cognitive-searchazure-search-.net-sdk

Azure Search: Indexed document count does not match the total number of uploaded records


I have been trying to upload 31 distinct records from the SQL server to azure cloud using Azure Search .NET SDK. I am able to upload the records without getting any technical errors. Even the logs confirm that all 31 records got indexed by return the status code as 200 for all 31 records

However in the azure portal when i see the document count on the index i only see 27. This means 4 records for some reason didnt get indexed. if two records have same party ids then only one gets uploaded. In order to avoid this i created a new key in the dto which is the combination of party id and tag id to ensure the keys are unique for every row. However this didnt help and i keep losing the rows which have duplicate partyIds.

Could someone please explain to me why the records are missing? i tried googling for related articles but no luck so far.

Below is the Object 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; }
}

Solution

  • Maybe this is possible you are sending duplicated data if you want to check please add this code you can find out where your 4 record going.

    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)));  
    }
    
    

    Note: in unikKey result can find out the actual result which one update or created in azure server.