Core
API v2.x
2

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.

This method also supports the Koncorde Filters DSL to match documents by passing the lang argument with the value koncorde.
Koncorde filters will be translated into an Elasticsearch query.

Koncorde bool operator and regexp clause are not supported for search queries.


Query Syntax #

HTTP #

Copied to clipboard!
URL: http://kuzzle:7512/<index>/<collection>/_count
Method: POST
Body:
Copied to clipboard!
{
  "query": {
    "match_all": {}
  }
}

Other protocols #

Copied to clipboard!
{
  "index": "<index>",
  "collection": "<collection>",
  "controller": "document",
  "action": "count",
  "body": {
    "query": {
      "match_all": {}
    }
  }
}

Kourou #

Copied to clipboard!
kourou document:count <index> <collection> <body>

Arguments #

  • collection: collection name
  • index: index name

Body properties #

Optional: #

  • query: the search query itself, using the ElasticSearch Query DSL or the Koncorde Filters DSL syntax.
  • lang: specify the query language to use. By default, it's elasticsearch but koncorde can also be used.
    Available since 2.19.10

Response #

Returns an object with the count property, an integer showing the number of documents matching the provided search query:

Copied to clipboard!
{
  "status": 200,
  "error": null,
  "index": "<index>",
  "collection": "<collection>",
  "controller": "document",
  "action": "count",
  "requestId": "<unique request identifier>",
  "result": {
    "count": 42
  }
}