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

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


Argument Type Description
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

Copied to clipboard!
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);
}