SDK
SDK Golang v1.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

MCreate #

Creates multiple documents.

Returns a partial error (error code 206) if one or more documents creations fail.

Arguments #

MCreate(
    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 an json.RawMessage containing the created documents.

Usage #

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