SDK
SDK Golang v3.x
2

Replace #

Replaces the content of an existing document.

Arguments #

Replace(
  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
Document ID
document
string
Document body
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 replaced document.

Usage #

kuzzle.Document.Create(
  "nyc-open-data",
  "yellow-taxi",
  "some-id",
  json.RawMessage(`{"color": "yellow"}`),
  nil)
response, err := kuzzle.Document.Replace(
  "nyc-open-data",
  "yellow-taxi",
  "some-id",
  json.RawMessage(`{
    "capacity": 4,
    "category": "sedan"
  }`),
  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
    },
    "created": false,
    "_source": {
      "capacity": 4,
      "category": "sedan",
      "_kuzzle_info": {
        "author": "-1",
        "createdAt": 1538641029988,
        "updatedAt": 1538641029988,
        "updater": "-1",
        "active": true,
        "deletedAt": null
      }
    },
    "_meta": {
      "author": "-1",
      "createdAt": 1538641029988,
      "updatedAt": 1538641029988,
      "updater": "-1",
      "active": true,
      "deletedAt": null
    }
  }
  */
  fmt.Println("Success")
}