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

Create #

Creates a new document in the persistent data storage.

Returns an error if the document already exists.

The optional parameter refresh can be used with the value wait_for in order to wait for the document to be indexed (indexed documents are available for search).

Arguments #

Create(
  index string,
  collection string,
  id string,
  document json.RawMessage,
  options types.QueryOptions) (json.RawMessage, error) {

ArgumentTypeDescription
index
string
Index name
collection
string
Collection name
id
string
Optional document id. If set to a blank string, will use a auto-generated id
document
json.RawMessage
Document content
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
Refresh
string

("")
If set to wait_for, waits for the change to be reflected for search (up to 1s)

Return #

Returns a json.RawMessage containing the document creation result.

NameTypeDescription
_idstringNewly created document ID
_versionintVersion of the document in the persistent data storage
_sourceobjectThe created document
result
string
Set to created in case of success and updated if the document already exists

Usage #

response, err := kuzzle.Document.Create("nyc-open-data", "yellow-taxi", "some-id", json.RawMessage(`{"lastName": "Eggins"}`), nil)
if err != nil {
  log.Fatal(err)
} else {
  fmt.Println(string(response))
  /*
  {
    "_index": "nyc-open-data",
    "_type": "yellow-taxi",
    "_id": "some-id",
    "_version": 1,
    "result": "created",
    "_shards": {
      "total": 2,
      "successful": 1,
      "failed": 0
    },
    "created": true,
    "_source": {
      "lastName": "Eggins",
      "_kuzzle_info": {
        "author": "-1",
        "createdAt": 1537445737667,
        "updatedAt": null,
        "updater": null,
        "active": true,
        "deletedAt": null
      }
    }
  }
  */
  fmt.Println("Success")
}