简体   繁体   English

如何使用NEST(Elasticsearch)UpdateByQuery更新多个字段?

[英]How to update multiple fields with NEST (Elasticsearch) UpdateByQuery?

I am using UpdateByQuery, I want to update multiple fields. 我正在使用UpdateByQuery,我想更新多个字段。 In Elasticsearch documentation it tells how to update a particular field. 在Elasticsearch文档中,它介绍了如何更新特定字段。 How to do it? 怎么做?

if you are using Nest you should use DocAsUpsert. 如果使用的是Nest,则应使用DocAsUpsert。 In order to do that do a query first, get the _id of the doc then update based on that. 为了做到这一点,首先要查询,获取文档的_id,然后根据该值进行更新。
Small example here, update by 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)
                     );

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

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