Search code examples
azureindexingazure-cognitive-search

Comparing data in an Azure Index to data that is about to be uploaded


I have an index using the Azure Cognitive Search service. I'm writing a program to automate the upload of new data to this index. I don't want to delete and re-create the index from scratch unnecessarily each time. Is there a way of comparing what is currently in the index with the data that I am about to upload, without having to download that data from there first and manually compare it? I have been looking at the MS documentation and other articles but cannot see a way to do this comparison?


Solution

  • you can use MergeOrUpload operation, so if it's not there it will insert, otherwise update.

    Please make sure the IDs are the same otherwise you'll endup always adding new items.

    IndexAction.MergeOrUpload(
        new Customer()
        {
            Id = "....",
            UpdatedBy = new 
            {
                Id = "..."
            }
        }
    )
    

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.search.models.indexactiontype?view=azure-dotnet