Skip to content

Commit f28cf33

Browse files
authored
Merge pull request #513 from kuzzleio/7.2.0-proposal
# [7.2.0](https://github.com/kuzzleio/sdk-javascript/releases/tag/7.2.0) (2020-04-28) #### Bug fixes - [ [#508](#508) ] Fix SearchResult.next with sort/size ([Aschen](https://github.com/Aschen)) - [ [#512](#512) ] Fix token expired ([Aschen](https://github.com/Aschen)) - [ [#511](#511) ] Avoid to mutate user options ([Aschen](https://github.com/Aschen)) - [ [#507](#507) ] Fix collection getMapping ([Aschen](https://github.com/Aschen)) #### New features - [ [#510](#510) ] Add security:refresh ([Yoann-Abbes](https://github.com/Yoann-Abbes)) #### Enhancements - [ [#509](#509) ] Add the rate limit property to Profile objects ([scottinet](https://github.com/scottinet)) ---
2 parents 72c79f8 + 55dc347 commit f28cf33

37 files changed

+507
-389
lines changed

.gitignore

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ doc/framework
1818
dead_links.json
1919

2020
# Cypress debug
21-
doc/6/getting-started/.react/cypress/screenshots
22-
doc/6/getting-started/.react/cypress/videos
23-
doc/6/getting-started/.vuejs/cypress/screenshots
24-
doc/6/getting-started/.vuejs/cypress/videos
21+
doc/7/getting-started/.react/cypress/screenshots
22+
doc/7/getting-started/.react/cypress/videos
23+
doc/7/getting-started/.vuejs/cypress/screenshots
24+
doc/7/getting-started/.vuejs/cypress/videos
25+
26+
# Debug snippets
27+
test-*.js
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
code: true
3+
type: page
4+
title: refresh
5+
---
6+
7+
# refresh
8+
9+
Forces an immediate [reindexation](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/docs-refresh.html) of the provided security collection.
10+
11+
The available security collections are: `users`, `profiles`, `roles`.
12+
13+
When writing or deleting documents in Kuzzle, the changes need to be indexed before being reflected in the search results.
14+
By default, this operation can take up to 1 second.
15+
16+
::: warning
17+
Forcing immediate refreshes comes with performance costs, and should only performed when absolutely necessary.
18+
:::
19+
20+
21+
```js
22+
refresh(collection);
23+
```
24+
25+
## Arguments
26+
27+
- `collection`: collection name to refresh
28+
29+
## Resolves
30+
31+
Resolves when the refresh has been done.
32+
33+
## Usage
34+
35+
<<< ./snippets/refresh.js
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
try {
2+
await kuzzle.security.refresh('users');
3+
console.log('Success');
4+
} catch (e) {
5+
console.error(e);
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: security#refresh
2+
description: Refreshes security collection
3+
hooks:
4+
template: default
5+
expected: Success

doc/7/core-classes/search-result/next/index.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ next();
2020

2121
Resolves to a `SearchResult` object, or to `null` if no more pages are available.
2222

23-
## Throw
23+
## Rejects
2424

25-
This method throws an exception if:
25+
This method returns a rejected promise with an error if:
2626

2727
- No pagination strategy can be applied (see below)
2828
- If invoking it would lead to more than 10 000 items being retrieved with the `from/size` strategy
@@ -56,19 +56,26 @@ You can restrict the scroll session maximum duration under the `services.storage
5656

5757
If the initial search contains `sort` and `size` parameters, the `next` method retrieves the next page of results following the sort order, the last item of the current page acting as a live cursor.
5858

59-
To avoid too many duplicates, it is advised to provide a sort combination that will always identify one item only. The recommended way is to use the field `_uid` which is certain to contain one unique value for each document.
59+
This strategy uses Elasticsearch [search_after](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/search-request-body.html#request-body-search-search-after) parameter.
60+
61+
::: warning
62+
You have to provide a sort combination that will always identify one item only. The recommended way is to use the field `_id` which is certain to contain one unique value for each document.
63+
To prevent partial retrieval of results, the SDK will reject with an error if the sort combination can identify multiple items.
64+
:::
6065

6166
Because this method does not freeze the search results between two calls, there can be missing or duplicated documents between two result pages.
6267

6368
This method efficiently mitigates the costs of scroll searches, but returns less consistent results: it's a middle ground, ideal for real-time search requests.
6469

70+
<<< ./snippets/sortsize.js
71+
6572
### Strategy: from / size
6673

6774
If the initial search contains `from` and `size` parameters, the `next` method retrieves the next page of result by incrementing the `from` offset.
6875

6976
Because this method does not freeze the search results between two calls, there can be missing or duplicated documents between two result pages.
7077

7178
It's the fastest pagination method available, but also the less consistent, and it is not possible to retrieve more than 10000 items using it.
72-
Above that limit, any call to `next` throws an Exception.
79+
Above that limit, any call to `next` will return a rejected promise with an error.
7380

7481
<<< ./snippets/fromsize.js
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
try {
2+
const documents = [];
3+
4+
for (let i = 0; i < 100; i++) {
5+
documents.push({ _id: `suv_no${i}`, body: { category: 'suv' } });
6+
}
7+
8+
await kuzzle.document.mCreate('nyc-open-data', 'yellow-taxi', documents, {
9+
refresh: 'wait_for'
10+
});
11+
12+
let results = await kuzzle.document.search(
13+
'nyc-open-data',
14+
'yellow-taxi',
15+
{
16+
query: { match: { category: 'suv' } },
17+
sort: [
18+
{ '_kuzzle_info.createdAt': 'desc' },
19+
'_id'
20+
]
21+
},
22+
{ size: 5 });
23+
24+
// Fetch the matched items by advancing through the result pages
25+
const matched = [];
26+
27+
while (results) {
28+
matched.push(...results.hits);
29+
results = await results.next();
30+
}
31+
32+
console.log(matched[0]);
33+
/*
34+
{ _id: 'suv_no1',
35+
_score: 0.03390155,
36+
_source:
37+
{ _kuzzle_info:
38+
{ author: '-1',
39+
updater: null,
40+
updatedAt: null,
41+
createdAt: 1570093133057 },
42+
category: 'suv' } }
43+
*/
44+
console.log(`Successfully retrieved ${matched.length} documents`);
45+
} catch (error) {
46+
console.error(error.message);
47+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: searchresult#sortsize
2+
description: Next method with sort/size
3+
hooks:
4+
before: |
5+
curl -XDELETE kuzzle:7512/nyc-open-data
6+
curl -XPOST kuzzle:7512/nyc-open-data/_create
7+
curl -XPUT kuzzle:7512/nyc-open-data/yellow-taxi
8+
after: |
9+
curl -XDELETE kuzzle:7512/nyc-open-data
10+
template: default
11+
expected: Successfully retrieved 100 documents

doc/7/getting-started/react-native/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This section deals with **Kuzzle V2** (+ **Javascript SDK 7**) and **React Nativ
1616

1717
- **Node.js** >= 12.0.0 ([install here](https://nodejs.org/en/download/))
1818
- **Running Kuzzle V2 Stack** ([instructions here](/core/2/guides/getting-started/running-kuzzle))
19-
- **Expo CLI** ([install here](https://docs.expo.io/versions/v36.0.0/get-started/installation/))
19+
- **Expo CLI** ([install here](https://docs.expo.io/get-started/installation))
2020

2121
"[Expo](https://docs.expo.io/versions/latest/) is a framework and a platform for universal React applications. It is a set of tools and services built around React Native and native platforms that help you develop, build, deploy, and quickly iterate on iOS, Android, and web apps from the same JavaScript/TypeScript codebase."
2222

0 commit comments

Comments
 (0)