【问题标题】:How to update multiple fields with NEST (Elasticsearch) UpdateByQuery?如何使用 NEST (Elasticsearch) UpdateByQuery 更新多个字段?
【发布时间】:2018-10-13 23:57:38
【问题描述】:

我正在使用 UpdateByQuery,我想更新多个字段。在 Elasticsearch 文档中,它讲述了如何更新特定字段。 怎么做?

【问题讨论】:

  • this documentation 中显示多个更新,例如:"ctx._source.last = params.last; ctx._source.nick = params.nick" - 你试过吗?

标签: c# elasticsearch nest


【解决方案1】:

如果您使用的是 Nest,则应使用 DocAsUpsert。为了做到这一点,首先进行查询,获取文档的 _id,然后根据它进行更新。
这里的小例子,通过 id 更新:

 var updateResponse = EsClient.Update<Business, object>(DocumentPath<Business>.Id(elasticId), u => u
                         .Index(_elasticIndex)
                         .Type("business")
                         .Doc(new Business { Field1 ="xxxx", Field2 ="yyyy" })
                         .DocAsUpsert()
                         .Refresh(Refresh.True)
                     );

【讨论】:

    猜你喜欢
    • 2023-01-26
    • 1970-01-01
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多