【问题标题】:How to update an Elasticsearch document in NEST2如何在 NEST2 中更新 Elasticsearch 文档
【发布时间】:2023-03-17 20:30:01
【问题描述】:

我已将我的代码移植到 NEST 2.0 和 Elasticsearch 2.0

我需要找到一种方法来更新已经存储到 ES2 中的文档

我使用的是partial object technique

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

如何使用 NEST2 做同样的事情?

【问题讨论】:

    标签: c# .net asp.net-web-api elasticsearch nest


    【解决方案1】:

    您传递文档 ID 的方式发生了一些变化。

    今天看起来像关注:

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

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

    希望对你有帮助。

    【讨论】:

    • 谢谢你,Rob,预计下周你的声望计数器会大幅增加。保证 ;-) 看起来你是唯一一个知道如何正确使用最新 NEST2 库的人
    • @GianlucaGhettini 上周我们一直在 Elasticon :)
    • 谢谢。不为我工作。他们的文件再次严重缺乏。也无法搜索我看到的文档。哦 - 从那以后,该方法的签名似乎发生了一些变化。 ElasticLowLowLevelClient.Update(字符串索引, 字符串类型, 字符串id, PostData body, [Func...])
    猜你喜欢
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-13
    • 1970-01-01
    相关资源
    最近更新 更多