SDK
SDK Golang v3.x
2

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 #

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

Argument Type Description
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

Option Type
(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.

Name Type Description
_id string Newly created document ID
_version int Version of the document in the persistent data storage
_source object The created document
result
string
Set to created in case of success and updated if the document already exists

Usage #

Copied to clipboard!
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")
}