I'm using Microsoft.Azure.Search version 3.0.1,
I'm trying the following:
// subset of my index's fields
private class SyncFields
{
public string Id { get; set; }
public DateTimeOffset? ApprovedOn { get; set; }
public DateTimeOffset? IgnoredOn { get; set; }
}
public void Sync()
{
var sync = new SyncFields
{
Id = "94303",
ApprovedOn = null,
IgnoredOn = DateTime.UtcNow
};
var searchClient = new SearchServiceClient("xxxx",
new SearchCredentials("xxxx"));
searchClient.SerializationSettings.NullValueHandling = NullValueHandling.Include;
using (var client = searchClient.Indexes.GetClient("xxxx"))
{
client.SerializationSettings.NullValueHandling = NullValueHandling.Include;
var batch = IndexBatch.Merge<SyncFields>(new[] { sync });
client.Documents.Index<SyncFields>(batch);
}
}
This isn't settings ApprovedOn
to null. It ignores it. If I set a non-null value, it does set it.
According to the documentation here the merge operation updates the field to be null. And in fact, if I make this Http post request manually with JSON, this is true. But the SDK isn't updating the field(s) to null. What am I missing?
This is a known limitation of the typed overloads of the Index
family of methods. The issue is described in detail here: https://github.com/Azure/azure-sdk-for-net/issues/1804
Some workarounds:
Index
instead for merge scenarios.Upload
instead of Merge
.[JsonProperty(NullValueHandling = NullValueHandling.Include)]
on the properties of your model class that you need to explicitly set to null in a merge operation (not recommended if you have many fields in your index).