c# - 使用 NEST 检查索引中是否存在文档

标签 c# elasticsearch elasticsearch-2.0 nest2

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

该方法刚刚在 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 文档的伟大和平。

关于c# - 使用 NEST 检查索引中是否存在文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37572287/

相关文章:

c# - 在 Docker 中运行 Blazor

elasticsearch - update_by_query用于多字段

elasticsearch - ELK : Unable to fetch mapping. 你有匹配模式的索引吗?

elasticsearch - 寻找 Elasticsearch updateByQuery 语法示例(节点驱动程序)

elasticsearch - Elasticsearch未分析字段

c# - 使用带有远程用户数据库的 Web 服务登录

c# - “日期”是 SoapElementAttribute 的无效值

javascript - 对于使用 XMLHttpRequest 更改其内容的页面来说,合适的事件监听器是什么?

Elasticsearch:文档大小和查询性能

java - 无法在elasticsearch 6.1.2的映射中插入 "index":"not_analyzed"