count #
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.
Signature #
int count(const std::string& index, const std::string& collection);
int count(
const std::string& index,
const std::string& collection,
const kuzzleio::query_options& options);
int count(
const std::string& index,
const std::string& collection,
const std::string& query);
int count(
const std::string& index,
const std::string& collection,
const std::string& query,
const kuzzleio::query_options& options);
Arguments #
Argument | Type | Description |
---|---|---|
index | const std::string& | Index name |
collection | const std::string& | Collection name |
query | const std::string& | JSON string representing the query to match |
options | kuzzleio::query_options* | Query options |
options #
Additional query options
Option | Type (default) | Description |
---|---|---|
queuable | bool ( true ) | If true, queues the request during downtime, until connected to Kuzzle again |
Return #
Returns the number of matched documents.
Exceptions #
Throws a kuzzleio::KuzzleException
if there is an error. See how to handle errors.
Usage #
try {
int count = kuzzle->document->count("nyc-open-data", "yellow-taxi", R"({
"query": {
"match": {
"license": "valid"
}
}
})");
std::cout << "Found " << count << " documents matching license:valid" << std::endl;
} catch (kuzzleio::KuzzleException& e) {
std::cerr << e.what() << std::endl;
}
Edit this page on Github(opens new window)