我正在使用 Microsoft.Azure.Search 3.0.1 版,
我正在尝试以下操作:
// 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);
}
}
这不是设置ApprovedOn
为空。它忽略它。如果我设置一个非空值,它会设置它。
根据此处的文档,合并操作将字段更新为空。事实上,如果我用 JSON 手动发出这个 Http post 请求,这是真的。但是 SDK 不会将字段更新为 null。我错过了什么?