我正在使用NEST进行Elasticsearch 6,并希望获得默认索引的文档数量。
documentation指的是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/testdocument/_count时,生成http://localhost:9200/test_docs/_count的URL
您可以使用
var countResponse = client.Count<TestDocument>(c => c.AllTypes());
这将调用API
GET http://localhost:9200/test_docs/_count