Skip to content

Upsert of a document (a dictionary) with null values doesn't insert those null values. #1004

Closed
@rogerk-unifysquare

Description

@rogerk-unifysquare

When writing a dictionary through the Update (with the document as Upsert; see below), all the values in the dictionary are not serialized and therefore not stored/updated on the document.

Consider:

Dictionary<string, string> test = new Dictionary<string, string>() {
{ "abc", null },
{ "def", "ghi" },
};

IUpdateResponse resp = client.Update<Dictionary<string, string>>(
ud => ud
.Type(DocumentType)
.Id("test")
.Doc(test)
.DocAsUpsert(true));

This results in the following request body:
{
"doc_as_upsert": true,
"doc": {
"def": "ghi"
}
}

i.e. the abc=null entry is missing. Also, setting the NullValueHandling property of the JsonSerializerSettings (through the SetJsonSerializerSettingsModifier method of the ConnectionSettings) doesn't fix this problem since it appears that the settings are only applied to the high-level request envelope, but not to the document. This basically seems to make it impossible to clear properties which were previsouly set without using scripts ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions