我正在重新编制索引,但每当我尝试删除不存在的文档时都会遇到问题,因此我需要检查该文档是否已存在。
该方法刚刚在 elasticsearch docs 中进行了解释.
我找到了 a question一些有趣的代码,我已经尝试过了
var docExists = client.DocumentExists<object>(d => d
.Index(indexname)
.Id(myId)
.Type("Abcdef"));
编译器报错
Cannot convert lambda expression to type 'Nest.DocumentPath<object>' because it's not a delegate type
我想我的错误是因为问题是指 NEST 1.x 而我使用的是 NEST 2.x。
我知道我可以做一个简单的查询,但我想知道是否有像 ES doc-exists 这样的直接方式.
谢谢
请您参考如下方法:
签名DocumentExists在 NEST 2.x 中改变了一点。
现在看起来像:
public IExistsResponse DocumentExists<T>(DocumentPath<T> document, Func<DocumentExistsDescriptor<T>, IDocumentExistsRequest> selector = null) where T : class
你的例子可以表达如下
client.DocumentExists<Document>(myId, d => d
.Index(indexname)
.Type("Abcdef"));
如果你对DocumentPath<T>感到好奇请阅读this NEST 文档的伟大和平。
