简体   繁体   English

如何在NEST2中更新Elasticsearch文档

[英]How to update an Elasticsearch document in NEST2

I have ported my code to NEST 2.0 and Elasticsearch 2.0 我已将代码移植到NEST 2.0和Elasticsearch 2.0

I need to find a way to update a document already stored into ES2 我需要找到一种方法来更新已存储到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? 如何使用NEST2做同样的事情?

The way how you are passing document id changed a bit. 你如何传递文档ID的方式改变了一点。

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. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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