replace #
Replaces the content of an existing document.
Arguments #
String replace(
String index,
String collection,
String id,
String body,
io.kuzzle.sdk.QueryOptions options
)
String replace(
String index,
String collection,
String id,
String body
)
Argument | Type | Description |
---|---|---|
index | String | Index name |
collection | String | Collection name |
id | String | Document ID |
body | 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 document.
Exceptions #
Throws a io.kuzzle.sdk.KuzzleException
if there is an error. See how to handle error.
Usage #
String doc = "{\"color\": \"yellow\"}";
try {
kuzzle.getDocument().create("nyc-open-data", "yellow-taxi", "some-id", doc);
String newDocument = "{"
+ " \"capacity\": 4,"
+ " \"category\": \"suv\""
+ "}";
String response = kuzzle.getDocument().replace(
"nyc-open-data",
"yellow-taxi",
"some-id",
newDocument
);
System.out.println(response);
/*
{
"_index": "nyc-open-data",
"_type": "yellow-taxi",
"_id": "some-id",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": false,
"_source": {
"capacity": 4,
"category": "sedan",
"_kuzzle_info": {
"author": "-1",
"createdAt": 1538641029988,
"updatedAt": 1538641029988,
"updater": "-1",
"active": true,
"deletedAt": null
}
}
}
*/
System.out.println("Success");
} catch (KuzzleException e) {
System.err.println(e.getMessage());
}
Edit this page on Github(opens new window)