Partial update elastic search NEST 2.x

2019-06-14 10:41发布

问题:

how can partial update a record in using NEST2?

I'm looking for an analog request: POST /erection/shop/1/_update {"doc": {"new":"0"}}

without recreating a new record. unfortunately I did not find anything about the updates in www.elastic.co/guide/en/elasticsearch/client/net-api/current/index.html

UPDATE:

var updateResponse = es.Current.Update<MyDocument, MyDocument>   (DocumentPath<MyDocument>.Id(2), descriptor => descriptor
     .Doc(new MyDocument
     {
         name = "new name"
     }));

I run this code, but it is fully updated the whole document.

result https://gyazo.com/2fdae851bb8bc445f6e8e58abb2f0e3b what am I doing wrong?

回答1:

Use anonymous object or another class with properties that you want update. try this code:

var updateResponse = es.Current.Update<MyDocument, object>(1, descriptor => descriptor
            .Doc(new { name = "new name" }));