如何在 NEST2 中更新 Elasticsearch 文档
本文关键字:更新 Elasticsearch 文档 NEST2 | 更新日期: 2023-09-27 18:36:08
我已经将我的代码移植到 NEST 2.0 和 Elasticsearch 2.0
我需要找到一种方法来更新已存储在 ES2 中的文档
我正在使用部分对象技术:
elastic.Update<myDocumentType, myPartialDocumentType>(u => u
.Index(myIndexName)
.Id(id)
.Doc(
new myPartialDocumentType()
{
// set the fields to update here
})
.Refresh());
如何使用 NEST2 做同样的事情?
传递文档 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"
}));
希望对您有所帮助。