Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions .github/workflows/pull_request.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,27 @@ jobs:
# sdk-version: 7
# cypress-key: ${{ secrets.CYPRESS_RECORD_KEY }}

documentation-dead-links:
name: Dead links
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- uses: actions/setup-node@v1.4.4
with:
node-version: "12"
- uses: ./.github/actions/dead-links
# documentation-dead-links:
# name: Dead links
# runs-on: ubuntu-18.04
# steps:
# - uses: actions/checkout@v2
# - name: Cache node modules
# uses: actions/cache@v2
# env:
# cache-name: cache-node-modules
# with:
# path: ~/.npm
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
# restore-keys: |
# ${{ runner.os }}-build-${{ env.cache-name }}-
# ${{ runner.os }}-build-
# ${{ runner.os }}-
# - uses: actions/setup-node@v1.4.4
# with:
# node-version: "12"
# - uses: ./.github/actions/dead-links

documentation-snippet-tests:
name: Documentation Snippet Tests
needs: [unit-tests]
Expand Down
42 changes: 21 additions & 21 deletions .github/workflows/push_master.workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,27 @@ jobs:
# sdk-version: 7
# cypress-key: ${{ secrets.CYPRESS_RECORD_KEY }}

documentation-dead-links:
name: Dead links
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- uses: actions/setup-node@v1.4.4
with:
node-version: "12"
- uses: ./.github/actions/dead-links
# documentation-dead-links:
# name: Dead links
# runs-on: ubuntu-18.04
# steps:
# - uses: actions/checkout@v2
# - name: Cache node modules
# uses: actions/cache@v2
# env:
# cache-name: cache-node-modules
# with:
# path: ~/.npm
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
# restore-keys: |
# ${{ runner.os }}-build-${{ env.cache-name }}-
# ${{ runner.os }}-build-
# ${{ runner.os }}-
# - uses: actions/setup-node@v1.4.4
# with:
# node-version: "12"
# - uses: ./.github/actions/dead-links

documentation-snippet-tests:
name: Documentation Snippet Tests
needs: [unit-tests]
Expand Down
50 changes: 50 additions & 0 deletions doc/7/controllers/bulk/update-by-query/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
code: true
type: page
title: updateByQuery
description: Updates documents matching query
---

# updateByQuery

<SinceBadge version="Kuzzle 2.11.0"/>
<SinceBadge version="7.7.1"/>

Updates documents matching the provided search query.

Kuzzle uses the [ElasticSearch Query DSL](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/query-dsl.html) syntax.

An empty or null query will match all documents in the collection.

<br/>

```js
updateByQuery(index, collection, query, changes, [options])
```

| Argument | Type | Description |
|---------------|-------------------|-------------------------------------------|
| `index` | <pre>string</pre> | Index name |
| `collection` | <pre>string</pre> | Collection name |
| `query` | <pre>object</pre> | Query to match |
| `changes` | <pre>object</pre> | Partial changes to apply to the documents |
| `options` | <pre>object</pre> | Optional parameters |

---

### options

Additional query options.

| Options | Type<br/>(default) | Description |
|-----------|----------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| `refresh` | <pre>string</pre><br/>(`""`) | If set to `wait_for`, waits for the change to be reflected for `search` (up to 1s) |
| [`timeout`](/sdk/7/core-classes/kuzzle/query#timeout) | <pre>number</pre> | Time (in ms) during which a request will still be waited to be resolved. Set it `-1` if you want to wait indefinitely |

## Resolves

Returns the number of updated documents.

## Usage

<<< ./snippets/update-by-query.js
17 changes: 17 additions & 0 deletions doc/7/controllers/bulk/update-by-query/snippets/update-by-query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
try {
const result = await kuzzle.bulk.updateByQuery(
'nyc-open-data',
'yellow-taxi',
{
match: {
capacity: 4
}
},
{ capacity: 42 });
console.log(result);
/**
* 2
*/
} catch (error) {
console.log(error.message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: bulk#updateByQuery
description: Update documents matching query
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
for i in 1 2 ; do
curl --fail -H "Content-type: application/json" -d '{"capacity": 4}' kuzzle:7512/nyc-open-data/yellow-taxi/document_$i/_create
done
for i in 1 2 3 4 5; do
curl --fail -H "Content-type: application/json" -d '{"capacity": 7}' kuzzle:7512/nyc-open-data/yellow-taxi/_create
done
curl -XPOST kuzzle:7512/nyc-open-data/yellow-taxi/_refresh
after:
- curl -XDELETE kuzzle:7512/nyc-open-data
template: default
expected: 2
92 changes: 92 additions & 0 deletions doc/7/controllers/document/m-upsert/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
code: true
type: page
title: mUpsert
description: Update documents
---

# mUpsert

<SinceBadge version="Kuzzle 2.11.0"/>
<SinceBadge version="7.7.1"/>

Applies partial changes to multiple documents. If a document doesn't already exist, a new document is created.

You can set the `retryOnConflict` optional argument (with a retry count), to tell Kuzzle to retry the failing updates the specified amount of times before rejecting the request with an error.

<br/>

```js
mUpsert(index, collection, documents, [options]);
```

| Argument | Type | Description |
|--------------|---------------------|------------------------------|
| `index` | <pre>string</pre> | Index name |
| `collection` | <pre>string</pre> | Collection name |
| `documents` | <pre>object[]</pre> | Array of documents to update |
| `options` | <pre>object</pre> | Query options |


### documents

`documents` is an array of object which each object representing a document. Fields `_id` and `changes` is always mandatory while `default` is optional.
Example:

```js
[
{
"_id": "<documentId>",
"changes": {
// document partial changes
},
"default": {
// optional: document fields to add to the "update" part if the document
// is created
}
},
{
"_id": "<anotherDocumentId>",
"changes": {
// document partial changes
},
}
]
```

### Options

Additional query options

| Options | Type<br/>(default) | Description |
|-------------------|----------------------------------|------------------------------------------------------------------------------------------|
| `queuable` | <pre>boolean</pre><br/>(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
| `refresh` | <pre>string</pre><br/>(`""`) | If set to `wait_for`, waits for the change to be reflected for `search` (up to 1s) |
| `retryOnConflict` | <pre>int</pre><br/>(`0`) | The number of times the database layer should retry in case of version conflict |
| `silent` | <pre>boolean</pre><br/>(`false`) | If `true`, then Kuzzle will not generate notifications <SinceBadge version="7.5.3"/> |

## Resolves

Returns an object containing 2 arrays: `successes` and `errors`

Each updated document is an object of the `successes` array with the following properties:

| Name | Type | Description |
|------------|-------------------|--------------------------------------------------------|
| `_id` | <pre>string</pre> | Document ID |
| `status` | <pre>number</pre> | HTTP error status |
| `created` | <pre>boolean</pre>| `true` if the document has been created |
| `_version` | <pre>number</pre> | Version of the document in the persistent data storage |
| `_source` | <pre>object</pre> | Document content |

Each errored document is an object of the `errors` array with the following properties:

| Name | Type | Description |
|------------|-------------------|-------------------------------|
| `document` | <pre>object</pre> | Document that cause the error |
| `status` | <pre>number</pre> | HTTP error status |
| `reason` | <pre>string</pre> | Human readable reason |

## Usage

<<< ./snippets/m-upsert.js
43 changes: 43 additions & 0 deletions doc/7/controllers/document/m-upsert/snippets/m-upsert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const doc1 = { capacity: 4 };
const doc2 = { capacity: 7 };

try {
await kuzzle.document.create('nyc-open-data', 'yellow-taxi', doc1, 'some-id');

const documents = [
{
_id: 'some-id',
changes: { category: 'sedan' }
},
{
_id: 'some-other-id',
changes: { category: 'limousine' },
default: { capacity: 8 }
}
];

const response = await kuzzle.document.mUpsert(
'nyc-open-data',
'yellow-taxi',
documents
);

console.log(response);
/*
{ successes:
[ { _id: 'some-id',
_source: { _kuzzle_info: [Object], category: 'sedan' },
_version: 2,
created: false,
status: 200 },
{ _id: 'some-other-id',
_source: { _kuzzle_info: [Object], category: 'limousine', capacity: 8 },
_version: 1,
created: true,
status: 200 } ],
errors: [] }
*/
console.log('Success');
} catch (error) {
console.error(error.message);
}
10 changes: 10 additions & 0 deletions doc/7/controllers/document/m-upsert/snippets/m-upsert.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: document#mUpsert
description: Update documents
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: default
expected: Success
Loading