SDK
SDK Golang v2.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.

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.

Arguments #

Count(
  index string,
  collection string,
  query json.RawMessage,
  options types.QueryOptions) (int, error)

ArgumentTypeDescription
index
string
Index name
collection
string
Collection name
query
json.RawMessage
Query to match
options
types.QueryOptions
A struct containing query options

options #

Additional query options

OptionType
(default)
Description
Queuable
bool

(true)
If true, queues the request during downtime, until connected to Kuzzle again

Return #

Returns the number of documents matching the given query.

Usage #

query := json.RawMessage(`{"query": {"match": {"licence": "valid"}}}`)
count, err := kuzzle.Document.Count("nyc-open-data", "yellow-taxi", query, nil)
if err != nil {
  log.Fatal(err)
} else {
  fmt.Printf("Found %d documents matching licence:valid\n", count)
}