繁体   English   中英

默认索引的 Elasticsearch NEST 文档计数

[英]Elasticsearch NEST Document count for default index

我正在为 Elasticsearch 6 使用 NEST,并希望获取默认索引的文档数。

文档是指 API 的 1.1 版本,它似乎不再起作用。

我使用默认索引创建了连接设置:

var connectionSettings = new ConnectionSettings().DefaultIndex("test_docs");

当我尝试 1.1 api 文档中的代码时:

var result = client.Count();

我收到以下错误:

无法从用法中推断出方法“ElasticClient.Count(Func, ICountRequest>)”的类型参数。 尝试明确指定类型参数。

当我提供一种类型时,它会附加到路径中。 例如:

client.Count<TestDocument>();

当我真正需要的是http://localhost:9200/test_docs/_count时,生成一个http://localhost:9200/test_docs/testdocument/_count的 URL

您可以使用

var countResponse = client.Count<TestDocument>(c => c.AllTypes());

它将调用API

GET http://localhost:9200/test_docs/_count

对于那些需要新方法的人(比如我自己)。 我将使用以下内容从特定索引中获取计数。

var countRequest = new CountRequest(Indices.Index("videos"));
long count = (await _ecClient.CountAsync(countRequest)).Count;

暂无
暂无

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

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