elasticsearch - 默认索引的 Elasticsearch NEST 文档计数
问题描述
我正在为 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
推荐阅读
- angular - 将事件显示为角度角度完整日历
- javascript - 如何使用 Async 和 await 从一个组件获取数据到另一个组件
- c# - 如何从 RESTful API 使用 C# 中的 ArrayList?
- javascript - 发布 ES2015 npm 包时有哪些问题?
- php - 使用 laravel 将数组数据存储在数据库中
- javascript - Swiper滑块过渡错误
- css - 为什么背景剪辑在 Edge 上不起作用?
- java - 如何解析所有子字段并在 Firebase 数据库中找到我需要的内容?
- c - 如何从函数返回双指针并将其作为输入发送到另一个函数?
- java - 无法通过套接字将 Python 消息发送到 Java