-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add document:upsert #38
Changes from 5 commits
0a3992c
721ad00
8dbf89b
9889a91
0126294
4c23d98
212abdb
90f9369
aeb5885
3d8c453
11fd5c9
d88c483
2b04dca
dc7c2bc
4891cf0
8c5f439
a9dcd0e
bca23bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,18 +20,35 @@ An empty or null query will match all documents in the collection. | |
|
||
|
||
```java | ||
public CompletableFuture<ConcurrentHashMap<String, ArrayList<Object>>> updateByQuery( | ||
public CompletableFuture<ConcurrentHashMap<String, ArrayList<Object>>> updateByQuery( | ||
String index, | ||
String collection, | ||
ConcurrentHashMap<String, Object> searchQuery, | ||
ConcurrentHashMap<String, Object> changes) throws NotConnectedException, InternalException | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad indentation |
||
|
||
public CompletableFuture<ConcurrentHashMap<String, ArrayList<Object>>> updateByQuery( | ||
String index, | ||
String collection, | ||
ConcurrentHashMap<String, Object> searchQuery, | ||
ConcurrentHashMap<String, Object> changes, | ||
Boolean waitForRefresh) throws NotConnectedException, InternalException | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad indentation |
||
|
||
public CompletableFuture<ConcurrentHashMap<String, ArrayList<Object>>> updateByQuery( | ||
String index, | ||
String collection, | ||
ConcurrentHashMap<String, Object> searchQuery, | ||
ConcurrentHashMap<String, Object> changes) throws NotConnectedException, InternalException | ||
|
||
public CompletableFuture<ConcurrentHashMap<String, ArrayList<Object>>> updateByQuery( | ||
ConcurrentHashMap<String, Object> changes, | ||
Boolean waitForRefresh, | ||
Integer retryOnConflict) throws NotConnectedException, InternalException | ||
|
||
public CompletableFuture<ConcurrentHashMap<String, ArrayList<Object>>> updateByQuery( | ||
String index, | ||
String collection, | ||
ConcurrentHashMap<String, Object> searchQuery, | ||
ConcurrentHashMap<String, Object> changes, | ||
UpdateOptions options) throws NotConnectedException, InternalException | ||
Boolean waitForRefresh, | ||
Integer retryOnConflict, | ||
Boolean source) throws NotConnectedException, InternalException | ||
``` | ||
|
||
| Argument | Type | Description | | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
--- | ||
code: true | ||
type: page | ||
title: upsert | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing description
Comment on lines
+3
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing description |
||
--- | ||
|
||
# upsert | ||
|
||
<SinceBadge version="Kuzzle 2.8.0"/> | ||
<SinceBadge version="auto-version" /> | ||
|
||
Applies partial changes to a document. If the document doesn't already exist, a new document is created. | ||
|
||
:::: tabs | ||
::: tab Java | ||
|
||
```java | ||
public CompletableFuture<ConcurrentHashMap<String, Object>> upsert( | ||
String index, | ||
String collection, | ||
ConcurrentHashMap<String, Object> changes) throws NotConnectedException, InternalException | ||
|
||
public CompletableFuture<ConcurrentHashMap<String, Object>> upsert( | ||
String index, | ||
String collection, | ||
ConcurrentHashMap<String, Object> changes, | ||
ConcurrentHashMap<String, Object> defaults) throws NotConnectedException, InternalException | ||
|
||
public CompletableFuture<ConcurrentHashMap<String, Object>> upsert( | ||
String index, | ||
String collection, | ||
ConcurrentHashMap<String, Object> changes, | ||
ConcurrentHashMap<String, Object> defaults, | ||
Boolean waitForRefresh) throws NotConnectedException, InternalException | ||
|
||
public CompletableFuture<ConcurrentHashMap<String, Object>> upsert( | ||
String index, | ||
String collection, | ||
ConcurrentHashMap<String, Object> changes, | ||
ConcurrentHashMap<String, Object> defaults, | ||
Boolean waitForRefresh, | ||
Integer retryOnConflict) throws NotConnectedException, InternalException | ||
|
||
public CompletableFuture<ConcurrentHashMap<String, Object>> upsert( | ||
String index, | ||
String collection, | ||
ConcurrentHashMap<String, Object> changes, | ||
ConcurrentHashMap<String, Object> defaults, | ||
Boolean waitForRefresh, | ||
Integer retryOnConflict, | ||
Boolean source) throws NotConnectedException, InternalException | ||
``` | ||
|
||
| Argument | Type | Description | | ||
| ------------ | ----------------- | ----------------------------------------- | | ||
| `index` | <pre>String</pre> | Index name | | ||
| `collection` | <pre>String</pre> | Collection name | | ||
| `id` | <pre>String</pre> | Document ID | | ||
| `changes` | <pre>ConcurrentHashMap<String, Object></pre> | Partial content of the document to update | | ||
|
||
### Options | ||
|
||
Additional query options | ||
|
||
| Options | Type<br/>(default) | Description | | ||
| ----------------- | ------------------------------- | ---------------------------------------------------------------------------------- | | ||
| `defaults` | <pre>ConcurrentHashMap<String, Object><br/>(`{}`) | (optional) fields to add to the document if it gets created | | ||
Yoann-Abbes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `waitForRefresh` | <pre>Boolean</pre><br/>(`""`) | If set to `true`, waits for the change to be reflected for `search` (up to 1s) | | ||
| `retryOnConflict` | <pre>Integer</pre><br/>(`10`) | The number of times the database layer should retry in case of version conflict | | ||
| `source` | <pre>Boolean</pre><br/>(`false`)| If true, returns the updated document inside the response | ||
|
||
|
||
## Returns | ||
|
||
A `ConcurrentHashMap<String, Object>` with the following properties: | ||
|
||
| Property | Type | Description | | ||
|------------- |--------------------------------------------- |--------------------------------- | | ||
| `_source` | <pre>ConcurrentHashMap<String, Object></pre> | Updated document (if `source` option set to true) | | ||
| `_id` | <pre>String</pre> | ID of the udated document | | ||
Yoann-Abbes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `_version` | <pre>Integer</pre> | Version of the document in the persistent data storage | | ||
| `created` | <pre>Boolean</pre> | ||
|
||
## Usage | ||
|
||
<<< ./snippets/upsert-java.java | ||
|
||
::: | ||
::: tab Kotlin | ||
|
||
```kotlin | ||
fun upsert( | ||
index: String, | ||
collection: String, | ||
id: String, | ||
changes: ConcurrentHashMap<String, Any?>, | ||
defaults: ConcurrentHashMap<String, Any?>, | ||
waitForRefresh: Boolean? = null, | ||
retryOnConflict: Int? = null, | ||
source: Boolean? = null): CompletableFuture<ConcurrentHashMap<String, Any?>> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bad indentation |
||
``` | ||
|
||
| Argument | Type | Description | | ||
| ------------ | ----------------- | ----------------------------------------- | | ||
| `index` | <pre>String</pre> | Index name | | ||
| `collection` | <pre>String</pre> | Collection name | | ||
| `id` | <pre>String</pre> | Document ID | | ||
| `changes` | <pre>ConcurrentHashMap<String, Any?></pre> | Partial content of the document to update | | ||
|
||
### Options | ||
|
||
Additional query options | ||
|
||
| Options | Type<br/>(default) | Description | | ||
| ----------------- | ------------------------------- | ---------------------------------------------------------------------------------- | | ||
| `defaults` | <pre>ConcurrentHashMap<String, Any?><br/>(`{}`) | (optional) fields to add to the document if it gets created | | ||
Yoann-Abbes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `waitForRefresh` | <pre>Boolean</pre><br/>(`""`) | If set to `true`, waits for the change to be reflected for `search` (up to 1s) | | ||
| `retryOnConflict` | <pre>Integer</pre><br/>(`10`) | The number of times the database layer should retry in case of version conflict | | ||
| `source` | <pre>Boolean</pre><br/>(`false`)| If true, returns the updated document inside the response | ||
|
||
|
||
## Returns | ||
|
||
A `ConcurrentHashMap<String, Any?>` with the following properties: | ||
Yoann-Abbes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
| Property | Type | Description | | ||
|------------- |--------------------------------------------- |--------------------------------- | | ||
| `_source` | <pre>ConcurrentHashMap<String, Any?></pre> | Updated document (if `source` option set to true) | | ||
| `_id` | <pre>String</pre> | ID of the udated document | | ||
Yoann-Abbes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `_version` | <pre>Integer</pre> | Version of the document in the persistent data storage | | ||
| `created` | <pre>Boolean</pre> | ||
|
||
## Usage | ||
|
||
<<< ./snippets/upsert-kotlin.kt | ||
|
||
::: | ||
:::: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
ConcurrentHashMap<String, Object> category = new ConcurrentHashMap<>(); | ||
ConcurrentHashMap<String, Object> changes = new ConcurrentHashMap<>(); | ||
category.put("category", "suv"); | ||
changes.put("changes", category); | ||
|
||
ConcurrentHashMap<String, Object> result = kuzzle | ||
.getDocumentController() | ||
.upsert("nyc-open-data", "yellow-taxi", "some-id", changes) | ||
.get(); | ||
|
||
/* | ||
{ | ||
created=true | ||
_id="some_id", | ||
version=1 | ||
} | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: java-document#upsert | ||
description: Applies a partial update to an existing document. | ||
hooks: | ||
before: | | ||
curl -XDELETE kuzzle:7512/nyc-open-data | ||
curl -XPOST kuzzle:7512/nyc-open-data/_create | ||
curl -XPUT kuzzle:7512/nyc-open-data/yellow-taxi | ||
after: | ||
template: print-result | ||
expected: "{created=true, _id=some-id, _version=1}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
val category: ConcurrentHashMap<String, Any?> = | ||
ConcurrentHashMap<String, Any?>().apply { | ||
put("category", "suv") | ||
} | ||
|
||
val changes: ConcurrentHashMap<String, Any?> = | ||
ConcurrentHashMap<String, Any?>().apply { | ||
put("changes", category) | ||
} | ||
|
||
val result: ConcurrentHashMap<String, Any?> = | ||
kuzzle | ||
.documentController | ||
.upsert("nyc-open-data", "yellow-taxi", "some-id", changes) | ||
.get() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing indentation |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: kotlin-document#upsert | ||
description: Applies a partial update to an existing document. | ||
hooks: | ||
before: | | ||
curl -XDELETE kuzzle:7512/nyc-open-data | ||
curl -XPOST kuzzle:7512/nyc-open-data/_create | ||
curl -XPUT kuzzle:7512/nyc-open-data/yellow-taxi | ||
after: | ||
template: print-result | ||
expected: "{created=true, _id=some-id, _version=1}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad indentation