SDK
SDK Golang v2.x
1

CreateOrReplace #

Creates a new document in the persistent data storage, or replaces its content if it 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!
CreateOrReplace(
  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
Document 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.CreateOrReplace(
  "nyc-open-data",
  "yellow-taxi",
  "some-id",
  json.RawMessage(`{"lastName": "McHan"}`),
  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": "McHan",
      "_kuzzle_info": {
        "author": "-1",
        "createdAt": 1537445737667,
        "updatedAt": null,
        "updater": null,
        "active": true,
        "deletedAt": null
      }
    }
  }
  */
  fmt.Println("Success")
}