Count in C# NEST for ES 5.5

Hi,

I'm writing a simple C# app that uses the NEST client for retrieving data from a local Elasticsearch instance. I have a small problem trying to get the number of all indexed (over all indices) documents. There is some documentation for the count() method for Elasticsearch 1.x here:

https://www.elastic.co/guide/en/elasticsearch/client/net-api/1.x/count.html

but the same site is not available for the current version, and also the simple .count() call doesn't work anymore as it requires some parameters.

I tried the search functionality on this forum because I think that this topic was somewhere discussed before, but all I've found were some count issues for nested documents - not a simple count() for indexed documents (without nested docs).

Could you please explain how to get the number of indexed documents in the current NEST client version?

Greetings
Martin

Ok, figured it out:

var settings = new ConnectionSettings(new Uri("http://server:9200"));
var client = new ElasticClient(settings);
var clusterStats = client.ClusterStats();
var docsCount = clusterStats.Indices.Documents.Count;

This returns the same number as using GET server:9200/_count

Greetings
Martin

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.