title: Elasticsearch NEST partial update of anonymous object with an empty nested object
body: <p>Trying to "reset" a nested object in a document but it will not set it back to empty.  </p>
  
  <p>I have a POCO:</p>
  
  <pre><code>public class StreetAddress 
  {
      public int HouseNumber { get; set; }
      public string Street { get; set; }
  }
  
  public class FullAddress
  {
      public string City{ get; set; }
  
      public string State { get; set; }
  
      public StreetAddress StreetAddress { get; set; }
  
      public int Zip { get; set; }
  
      public List&lt;string&gt; Codes { get; set; }
  }
  </code></pre>
  
  <p>So currently if I created this new document for FullAddress with the StreetAddress already set the document looks like this when queried:</p>
  
  <pre><code>"_source": {          
      "city": "Los Angeles",          
      "state": "California",          
      "zip": 90019,            
      "streetAddress": {            
          "houseNumber": 1,
          "street": "Apple Street"          
      },
      "codes" : [
          { "la-601" }
      ]     
  }
  </code></pre>
  
  <p>Now I want to call NEST client update to reset the StreetAddress nested object:</p>
  
  <pre><code>StreetAddress localStreetAddress = new StreetAddress();
  
  var partialAddress = new 
  { 
      City = "NewCity",
      Zip = 11111,
      StreetAddress = localStreetAddress
  };
  
  this._client.Update&lt;ElasticsearchProject, object&gt;(update =&gt; update
      .Id(1) 
      .Doc(partialAddress)
  );
  </code></pre>
  
  <p>The final outcome I was hoping for when I query would be after the above update call:</p>
  
  <pre><code>"_source": {          
      "city": "NewCity",          
      "state": "California",          
      "zip": 11111,            
      "streetAddress": {}     
  }
  </code></pre>
  
  <p>However, the partial update does two things that is undesired:</p>
  
  <ol>
  <li>It only updates the City and Zip fields and leaves the StreetAddress
  as it was before and doesn't clear it out to empty or null.  </li>
  <li>It clears out the Codes list to empty since the partial update doesn't include the list.</li>
  </ol>
  
  <p>I know I can set the StreetAddress to null and add the JSON property to include null like this:</p>
  
  <pre><code>[JsonProperty(NullValueHandling = NullValueHandling.Include)]
  public StreetAddress StreetAddress { get; set; }
  </code></pre>
  
  <p>but all that would result is that the document update would set it to null and not empty and I am not sure if that is a desired result for the document:</p>
  
  <pre><code>"_source": {          
          "city": "NewCity",          
          "state": "California",          
          "zip": 11111,            
          "streetAddress": null     
      }
  </code></pre>
  
  <p>Not sure if there was a way to do a partial update without going down the script path to set the nested object back to empty.</p>