SDK
SDK C# v1.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

CountAsync #

Counts documents in a collection.

A query can be provided to alter the count result, otherwise returns the total number of documents in the collection.

Kuzzle uses the ElasticSearch Query DSL syntax.

Arguments #

public async Task<int> CountAsync(
  string index, 
  string collection, 
  JObject query = null);

ArgumentTypeDescription
index
string
Index name
collection
string
Collection name
query
JObject
JObject representing the query to match

Return #

Returns the number of matched documents.

Exceptions #

Throws a KuzzleException if there is an error. See how to handle errors.

Usage #

try {
  JObject query = JObject.Parse(@"{
    ""query"": {
      ""match"": {
        ""license"": ""valid""
      }
      }
    }");
  int count = await kuzzle.Document.CountAsync("nyc-open-data", "yellow-taxi", query);
  Console.WriteLine($"Found {count} documents matching license:valid");
} catch (KuzzleException e) {
  Console.Error.WriteLine(e);
}