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.

Query #

Base method used to send queries to Kuzzle, following the API Documentation.

This is a low-level method, exposed to allow advanced SDK users to bypass high-level methods.

Arguments #

Query(request *types.KuzzleRequest, options types.QueryOptions, responseChannel chan<- *types.KuzzleResponse)
ArgumentTypeDescription
request
*types.KuzzleRequest
API request options
options
types.QueryOptions
Additional query options
responseChannel
chan<- *types.KuzzleResponse
A channel to receive the API response

request #

Properties required for the Kuzzle API can be set in the KuzzleRequest. The following properties are the most common.

PropertyTypeDescription
Controller
string
Controller name
Action
string
Action name
Body
interface{}
Query body for this action
Index
string
Index name for this action
Collection
string
Collection name for this action
Id
string
id for this action
Volatile
VolatileData
Additional information to send to Kuzzle

options #

A QueryOptions containing additional query options Theses properties can bet Get/Set. The following properties are the most common.

PropertyTypeDescriptionDefault
Queuable
bool
Make this request queuable or nottrue

responseChannel #

A channel to receive the API response. This channel will receive a KuzzleResponse

Usage #

request := types.KuzzleRequest{
  Controller: "document",
  Action:     "create",
  Id:         "my-custom-document-id",
  Index:      "nyc-open-data",
  Collection: "yellow-taxi",
  Body:       json.RawMessage("{\"trip_distance\": 4.23, \"passenger_count\": 2}"),
}
options := types.NewQueryOptions()
options.SetRefresh("wait_for")
ch := make(chan *types.KuzzleResponse)
go kuzzle.Query(&request, options, ch)
response := <-ch
if response.Status == 200 {
  fmt.Println("Document created")
} else {
  fmt.Println(response.Error.Message)
}