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.

createOrReplace #

Creates a new document in the persistent data storage, or replaces its content if it 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 createOrReplace(
  String index,
  String collection,
  String id,
  String documents,
  io.kuzzle.sdk.QueryOptions options
)
String createOrReplace(
  String index,
  String collection,
  String id,
  String documents
)

Argument Type Description
index
String
Index name
collection
String
Collection name
id
String
Document ID
documents
String
A JSON String containing the body of the document
options
io.kuzzle.sdk.QueryOptions
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 updated/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().createOrReplace(
    "nyc-open-data",
    "yellow-taxi",
    "some-id",
    "{\"lastName\": \"McHan\"}"
  );
  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": {
      "licence": "valid",
      "_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());
}