Allowing Date time null value to update in Bulk API using OpenSerch.Net

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):
OpenSearch.Net v1.2.0

Describe the issue:
Hi we are using Bulk API to update multiple documents at the same time.

We have following Schema Classes in .Net. I have removed some non required fields. we are using Newtonsoft.Json

 [OpenSearchType(IdProperty = "id", RelationName = "instant_offer")]
 public class InstantOfferDetailDto
 {
     /// <summary>
     /// Nullable Instant offer id because it can be null when clone and assign offer
     /// </summary>
     [Number(Name = "id")]
     public long? Id { get; set; }

     [JsonProperty(NullValueHandling = NullValueHandling.Include)]
     [Object(Name = "offer")]
     public OfferDetailDto Offer { get; set; }
}

 public class OfferDetailDto
 {
      [JsonProperty(NullValueHandling = NullValueHandling.Include)]
      [Date(Name = "assign_date")]
      public DateTime? AssignDate { get; set; }
}

Configuration:
While using Bulk API we checked that Null Values are passed to Bulk API request, but it seems API does not update value to null and keep as it is. I checked DebugInformation and that assign_date did not exist in that request.

Do you know how can I set null value to Datetime property thought it is Nullable in c#?

Relevant Logs or Screenshots:

Hi @SagarViradiya,

Are you able to share your client configuration? As it will help me to debug and reproduce the issue myself more quickly.

We are using .Net 4.7.

OpenSearch Connection

 var connectionSettings = new ConnectionSettings(node)
                .PrettyJson()
                .DisableDirectStreaming()
                .RequestTimeout(TimeSpan.FromMinutes(2)).DefaultIndex(indexName);

Index Schema:

{
  "instant_offer": {
    "mappings": {
      "properties": {
        "id": {
          "type": "long"
        },
        "offer": {
          "properties": {
            "assign_date": {
              "type": "date"
            }
          }
        }
      }
    }
  }
}

Let us know other thing you need.

@SagarViradiya If you’re wanting to use Newtonsoft.Json, you’ll need to take a dependency on OpenSearch.Client.JsonNetSerializer and configure the client to use it like so:

new ConnectionSettings(pool, JsonNetSerializer.Default)

// OR, if you want the behaviour of ignoring nulls except when specified:
new ConnectionSettings(pool, (b, v) => new JsonNetSerializer(b, v, () => new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }))

Ok, I will try out and let you know.

It seems working. But do you know if it is somewhere documented and have Test case in OpenSearch Library documentation? because I think it is common issue.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.