2

我正在重新索引我的索引,但每当我尝试删除一个不存在的文档时都会遇到问题,因此我需要检查该文档是否已经存在。

该方法只是在elasticsearch 文档中进行了解释。

我发现了一个包含一些有趣代码的问题,我已经尝试过

var docExists = client.DocumentExists<object>(d => d
    .Index(indexname)
    .Id(myId)
    .Type("Abcdef"));

但是编译器给出了一个错误

无法将 lambda 表达式转换为类型“Nest.DocumentPath<object>”,因为它不是委托类型

我想我的错误是因为问题是指 NEST 1.x 而我使用的是 NEST 2.x。

我知道我可以做一个简单的查询,但我想知道是否有像 ES doc-exists这样的直接方式。

谢谢

4

2 回答 2

4

DocumentExistsNEST 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>请阅读这份NEST 文档的伟大和平。

于 2016-06-01T18:11:16.037 回答
2

我最终使用

client.DocumentExists(new DocumentExistsRequest(indexName, type.Name, myId))

因为我不能使用通用方法DocumentExists<T>(..)

于 2017-01-31T14:38:59.743 回答