簡體   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