简体   繁体   中英

How to update an Elasticsearch document in NEST2

I have ported my code to NEST 2.0 and Elasticsearch 2.0

I need to find a way to update a document already stored into ES2

I was using the partial object technique :

        elastic.Update<myDocumentType, myPartialDocumentType>(u => u
            .Index(myIndexName)
            .Id(id)
            .Doc(
                new myPartialDocumentType()
                {
                    // set the fields to update here
                })
            .Refresh());

How to do the same thing using NEST2?

The way how you are passing document id changed a bit.

Looks like follow today:

var updateResponse = client.Update<Document, DocumentPartial>(1, descriptor => descriptor
        .Doc(new DocumentPartial
        {
            Title = "new title"
        }));

or

var updateResponse = client.Update<Document, DocumentPartial>(DocumentPath<Document>.Id(1), descriptor => descriptor
    .Doc(new DocumentPartial
    {
        Title = "new title"
    }));

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM