Update #
Updates a document content.
Conflicts may occur if the same document gets updated multiple times within a short timespan, in a database cluster. You can set the retryOnConflict
optional argument (with a retry count), to tell Kuzzle to retry the failing updates the specified amount of times before rejecting the request with an error.
Arguments #
Update(
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 | string | Document body |
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) |
RetryOnConflict | int ( 0 ) | Number of times the database layer should retry in case of version conflict |
Return #
Returns a json.RawMessage containing the document update result.
Name | Type | Description |
---|---|---|
_id | string | Newly created document ID |
_version | int | Version of the document in the persistent data storage |
result | string | Set to updated in case of success |
Usage #
kuzzle.Document.Create(
"nyc-open-data",
"yellow-taxi",
"some-id",
json.RawMessage(`{"capacity": 4}`),
nil)
response, err := kuzzle.Document.Update(
"nyc-open-data",
"yellow-taxi",
"some-id",
json.RawMessage(`{"category": "suv"}`),
nil)
if err != nil {
log.Fatal(err)
} else {
fmt.Println(string(response))
/*
{
"_index": "nyc-open-data",
"_type": "yellow-taxi",
"_id": "some-id",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
}
}
*/
}
Edit this page on Github(opens new window)