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

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)
}