import


Performing a bulk import on a data collection

Since Kuzzle v1.0.0

URL: http://kuzzle:7512/<index>/<collection>/_bulk
Method: POST
Body:

{
  // Data mapping using ElasticSearch bulk syntax.
  "bulkData": [
    {"create": {}},
    {"a": "document", "with": "any", "number": "of fields"},
    {"create": {}},
    {"another": "document"},
    {"create": {}},
    {"and": {"another": "one"}},
    {"...": "..."}
  ]
}

Query

{
  "index": "<index>",
  "collection": "<collection>",
  "controller": "bulk",
  "action": "import",

  "body": {
    "bulkData": [
      {"create": {}},
      {"a": "document", "with": "any", "number": "of fields"},
      {"create": {}},
      {"another": "document"},
      {"create": {}},
      {"and": {"another": "one"}},
      {"...": "..."}
    ]
  }
}

Response

{
  "status": 200,
  "error": null,
  "index": "<index>",
  "collection": "<collection>",
  "controller": "bulk",
  "action": "import",
  "requestId": "<unique request identifier>",
  "result": {
    // The list of executed queries, with their status
    "hits": [
      {
        "create": {
          "_id": "<documentId>",
          "status": "<HTTP status code>"
        }
      },
      {
        "create": {
          "_id": "<documentId>",
          "status": "<HTTP status code>"
        }
      },
      {
        "create": {
          "_id": "<documentId>",
          "status": "<HTTP status code>"
        }
      }
    ]
  }
}

You can use the bulk import to save a list of documents in one specific collection in a specified index.
In such case, the collection in which the documents need to be inserted needs to be specified in the query.

In case a subset of the queries sent within the request fail, the client will receive a PartialError object.


Performing a global bulk import

Since Kuzzle v1.0.0

URL: http://kuzzle:7512/_bulk
Method: POST
Body:

{
  // Data mapping using ElasticSearch bulk syntax.
  "bulkData": [
    {"create": {"_index": "<index>", "_type": "<collection>"}},
    {"a": "document", "with": "any", "number": "of fields"},
    {"create": {"_index": "<index>", "_type": "<collection>"}},
    {"another": "document"},
    {"create": {"_index": "<index>", "_type": "<collection>"}},
    {"and": { "another": "one"} },
    ...
    {"create": {"index": { "_index": "<another index>", "_type": "<another collection>" }}}
  ]
}

Query

{
  "controller": "bulk",
  "action": "import",

  "body": {
    "bulkData": [
      {"create": {"_index": "<index>", "_type": "<collection>"}},
      {"a": "document", "with": "any", "number": "of fields"},
      {"create": {"_index": "<index>", "_type": "<collection>"}},
      {"another": "document"},
      {"create": {"_index": "<index>", "_type": "<collection>"}},
      {"and": { "another": "one"} },
      {"create": {"index": { "_index": "<another index>", "_type": "<another collection>" }}}
    ]
  }
}

Response

{
  "status": 200,
  "error": null,
  "controller": "bulk",
  "action": "import",
  "requestId": "<unique request identifier>",
  "result": {
    // The list of executed queries, with their status
    "hits": [
      {
        "create": {
          "_id": "<documentId>",
          "status": "<HTTP status code>"
        }
      },
      {
        "create": {
          "_id": "<documentId>",
          "status": "<HTTP status code>"
        }
      },
      {
        "create": {
          "_id": "<documentId>",
          "status": "<HTTP status code>"
        }
      }
    ]
  }
}

The bulk import can also be used in a more versatile (yet a little more verbose) way, to execute operations on a whole database, modifying multiple data collections in different indexes at once.
The collections to modify then need to be specified inside the query message,using the _typeargument, as specified in the ElasticSearch Bulk API.