upsert #
Available since Kuzzle 2.8.0
Available since 2.2.0
Applies partial changes to a document. If the document doesn't already exist, a new document is created.
Future<Map<String, dynamic>> upsert(
String index,
String collection,
String id,
Map<String, dynamic> changes, {
bool waitForRefresh = false,
int retryOnConflict,
bool source,
})
Argument | Type | Description |
---|---|---|
index | String | Index name |
collection | String | Collection name |
id | String | Document ID |
changes | Map<String, dynamic> | Partial content of the document to update |
Options #
Additional query options
Options | Type (default) | Description |
---|---|---|
defaults | Map<String, dynamic> ( {} ) | (optional) fields to add to the document if it gets created |
waitForRefresh | bool ( "" ) | If set to true , waits for the change to be reflected for search (up to 1s) |
retryOnConflict | int ( 10 ) | The number of times the database layer should retry in case of version conflict |
source | bool ( false ) | If true, returns the updated document inside the response |
Returns #
A Map<String, dynamic>
with the following properties:
Property | Type | Description |
---|---|---|
_source | Map<String, dynamic> | Updated document (if source option set to true) |
_id | String | ID of the udated document |
_version | int | Version of the document in the persistent data storage |
created | bool | If true , a new document was created, otherwise the document existed and was updated |
Usage #
final result = await kuzzle
.document
.upsert('nyc-open-data', 'yellow-taxi', 'some-id', {
'changes': { 'category': 'suv' },
},
);
Edit this page on Github(opens new window)