SDK
SDK Golang v3.x
2

MCreateOrReplace #

Creates or replaces multiple documents.

Returns a partial error (error code 206) if one or more document creations/replacements fail.

Arguments #

MCreateOrReplace(
    index string,
    collection string,
    documents json.RawMessage,
    options types.QueryOptions) (json.RawMessage, error)

ArgumentTypeDescription
index
string
Index name
collection
string
Collection name
documents
json.RawMessage
JSON array of documents to create
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 two arrays, successes and errors.

Each created or replaced document is an object of the successes array with the following properties:

NameTypeDescription
_id
string
Document ID
_version
int
Version of the document in the persistent data storage
_source
json.RawMessage
Document content
created
bool
True if the document was created

Each errored document is an object of the errors array with the following properties:

NameTypeDescription
document
json.RawMessage
Document that caused the error
status
int
HTTP error status
reason
string
Human readable reason

Usage #

body := json.RawMessage(`[
  {
    "_id": "some-id",
    "body": { "capacity": 4 }
  },
  {
    "_id": "some-other-id",
    "body": { "capacity": 4 }
    }
  ]`)
response, err := kuzzle.Document.MCreateOrReplace(
  "nyc-open-data",
  "yellow-taxi",
  body,
  nil)
if err != nil {
  log.Fatal(err)
} else {
  fmt.Println(string(response))
  /*
  {
    "successes": [
      {
        "_id":"some-id",
        "_source":{
          "_kuzzle_info":{
            "active":true,
            "author":"-1",
            "updater":null,
            "updatedAt":null,
            "deletedAt":null,
            "createdAt":1538552685790
          },
          "capacity":4
        },
        "_index":"nyc-open-data",
        "_type":"yellow-taxi",
        "_version":1,
        "result":"created",
        "_shards":{
          "total":2,
          "successful":1,
          "failed":0
        },
        "created":true,
        "status":201,
        "_meta":{
          "active":true,
          "author":"-1",
          "updater":null,
          "updatedAt":null,
          "deletedAt":null,
          "createdAt":1538552685790
        }
      },
      {
        "_id":"some-other-id",
        "_source":{
          "_kuzzle_info":{
            "active":true,
            "author":"-1",
            "updater":null,
            "updatedAt":null,
            "deletedAt":null,
            "createdAt":1538552685790
          },
          "capacity":4
        },
        "_index":"nyc-open-data",
        "_type":"yellow-taxi",
        "_version":1,
        "result":"created",
        "_shards":{
          "total":2,
          "successful":1,
          "failed":0
        },
        "created":true,
        "status":201,
        "_meta":{
          "active":true,
          "author":"-1",
          "updater":null,
          "updatedAt":null,
          "deletedAt":null,
          "createdAt":1538552685790
        }
      }
    ],
    "errors": []
  }
  */
  fmt.Println("Success")
}