Azure Index update a single field

Matthew Butler asked on December 18, 2023 15:17

I have a search index with a complex object and would like to periodically update a single field against multiple records, rather than a complete update of that item. Any ideas? Thanks

Correct Answer

Matthew Butler answered on December 19, 2023 09:13

  using (var serviceClient = new SearchServiceClient(indexinfo.IndexSearchServiceName, new SearchCredentials(indexinfo.IndexAdminKey)))
  { 
  var azureIndex = serviceClient.Indexes.GetClient(NamingHelper.GetValidIndexName(indexinfo.IndexName));

  var actions = productPages.Select(x =>
  {
      var price = AsyncUtil.RunSync(() => _priceCalculator.Calculate(x.NodeSKUID, qty: 1));

      return IndexAction.Merge(new Document
      {
          { "sys_id", $"{x.NodeID}-{x.DocumentID}" },
          { "price", price.PriceExVat }
      });
  }).ToArray();

  var result = azureIndex.Documents.Index(new IndexBatch<Document> { Actions = actions });
  }
0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.