SDK
SDK Java 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.

This SDK has been deprecated because of stability issues. It is not advised to use it in a production environment.

create #

Creates a new document in the persistent data storage.

Throws an error if the document already exists.

The optional parameter refresh can be used with the value wait_for in order to wait for the document to be indexed (indexed documents are available for search).

Arguments #

Copied to clipboard!
String create(
  String index,
  String collection,
  String id,
  String document,
  io.kuzzle.sdk.QueryOptions options
)
String create(
  String index,
  String collection,
  String id,
  String document
)

Argument Type Description
index
String
Index name
collection
String
Collection name
id
String
Optional document id. If set to a blank string, will use a auto-generated id
document
String
A JSON string containing the body of the document
options
io.kuzzle.sdk.QueryOptions
The query options.

options #

Additional query options

Option Type
(default)
Description
queuable
boolean

(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 string containing the created document.

Exceptions #

Throws a io.kuzzle.sdk.KuzzleException if there is an error. See how to handle errors.

Usage #

Copied to clipboard!
try {
  String response = kuzzle.getDocument().create(
    "nyc-open-data",
    "yellow-taxi",
    "some-id",
    "{\"lastName\": \"Eggins\"}"
  );
  System.out.println(response);
  /*
  {
    "_index": "nyc-open-data",
    "_type": "yellow-taxi",
    "_id": "some-id",
    "_version": 1,
    "result": "created",
    "_shards": {
      "total": 2,
      "successful": 1,
      "failed": 0
    },
    "created": true,
    "_source": {
      "lastName": "Eggins",
      "_kuzzle_info": {
        "author": "-1",
        "createdAt": 1537445737667,
        "updatedAt": null,
        "updater": null,
        "active": true,
        "deletedAt": null
      }
    }
  }
  */
  System.out.println("Success");
} catch (KuzzleException e) {
  System.err.println(e.getMessage());
}