Nest updatebyquery 我如何使用 poco 而不是编写脚本

Nest updatebyquery how can i use a poco instead of writing the script

我们有一个包含大约 200 万个文档的弹性索引,我需要一种方法来根据单个唯一字段更新它们的列表。我试过的是在 Nest 中使用内置的 updatebyquery 函数,但是我发现的文档要求我在我的代码中手动编写更新脚本,如下所示:

foreach (var document in batch)
{
    var script = "ctx._source.brand_no = params.brandNo;" +
                 "ctx._source.order_no = params.orderNo";

    var paramDict = new Dictionary<string, object>(){
        {"brandNo",document.BrandNo},
        {"orderNo",document.OrderNo}
    };

    await _clientProvider.ElasticClient
                         .UpdateByQueryAsync<Orderline>(x =>
                             x.Index(indexName).Query(q =>
                                 q.Term(t =>
                                     t.Field(f =>
                                         f.OrderLineID).Value(document.OrderLineID))).Script(s =>
                                 s.Source(script).Params(paramDict))));
}

我的问题是我的 Orderline class 相当大,而且这个硬编码脚本很容易出错且难以维护。

另一个问题是,此更新需要很长时间才能更新 200 万行。

My problem is that my Orderline class is pretty big, and this hardcoded script is very error prone and hard to maintain.

Update by query API 仅支持使用脚本更新,因此您可以实现一个小组件,从给定的 POCO 实例生成脚本,以减少脚本中出错的可能性。

Another issue is that this update takes a long time for 2 million rows.

将文档索引到新索引中,并 using aliases 指向更新版本的索引是否适用于您的情况? Updating/Deleting 现有索引中的数百万文档是一项相对 昂贵的操作。