Skip to content

Commit 1b5ec25

Browse files
committed
feat(collection): add flag to reindex collection after an update
1 parent 8164953 commit 1b5ec25

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

doc/7/controllers/collection/update/index.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ update(index, collection, definition);
2727
<br/>
2828

2929
| Arguments | Type | Description |
30-
|--------------|-------------------|-------------------------------------------------------------|
30+
| ------------ | ----------------- | ----------------------------------------------------------- |
3131
| `index` | <pre>string</pre> | Index name |
3232
| `collection` | <pre>string</pre> | Collection name |
3333
| `definition` | <pre>object</pre> | Describes the collection mappings and the ES index settings |
@@ -37,39 +37,41 @@ update(index, collection, definition);
3737

3838
Additional query options
3939

40-
| Options | Type<br/>(default) | Description |
41-
| ---------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
42-
| `queuable` | <pre>boolean</pre><br/>(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
43-
| `refresh` | <pre>string</pre><br/>(`""`) | If set to `wait_for`, waits for the change to be reflected for `search` (up to 1s) |
44-
| [`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 |
45-
40+
| Options | Type<br/>(default) | Description |
41+
| ----------------------------------------------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
42+
| `queuable` | <pre>boolean</pre><br/>(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
43+
| `refresh` | <pre>string</pre><br/>(`""`) | If set to `wait_for`, waits for the change to be reflected for `search` (up to 1s) |
44+
| [`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 |
4645

4746
<SinceBadge version="7.4.0">
4847

4948
### definition
5049

5150
An object containing:
52-
- [collection mappings](/core/2/guides/main-concepts/data-storage).
53-
- Elasticsearch [index settings](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/index-modules.html#index-modules-settings)
5451

52+
- [collection mappings](/core/2/guides/main-concepts/data-storage).
53+
- Elasticsearch [index settings](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/index-modules.html#index-modules-settings)
54+
- `reindexCollection` (optional): if set to `true`, Kuzzle will reindex the collection after updating the mappings. This is useful when you want to update the mappings of a collection that already contains data.
5555

5656
```js
5757
const definition = {
5858
mappings: {
5959
properties: {
60-
field1: { type: 'text' },
60+
field1: { type: "text" },
6161
field2: {
6262
properties: {
63-
nestedField: { type: 'keyword' }
64-
}
65-
}
66-
}
63+
nestedField: { type: "keyword" },
64+
},
65+
},
66+
},
6767
},
68+
reindexCollection: true,
6869
settings: {
6970
// index settings (e.g. analyzers)
70-
}
71+
},
7172
};
7273
```
74+
7375
</SinceBadge>
7476

7577
<DeprecatedBadge version="7.4.0" >
@@ -83,13 +85,13 @@ The mappings must have a root field `properties` that contain the mappings prope
8385
```js
8486
const mappings = {
8587
properties: {
86-
field1: { type: 'text' },
88+
field1: { type: "text" },
8789
field2: {
8890
properties: {
89-
nestedField: { type: 'keyword' }
90-
}
91-
}
92-
}
91+
nestedField: { type: "keyword" },
92+
},
93+
},
94+
},
9395
};
9496
```
9597

src/controllers/Collection.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { BaseController } from "./Base";
21
import { SpecificationsSearchResult } from "../core/searchResult/Specifications";
3-
import { CollectionMappings, JSONObject, ArgsDefault } from "../types";
2+
import { ArgsDefault, CollectionMappings, JSONObject } from "../types";
3+
import { BaseController } from "./Base";
44

55
export class CollectionController extends BaseController {
66
constructor(kuzzle) {
@@ -310,6 +310,10 @@ export class CollectionController extends BaseController {
310310
* Mappings definition
311311
*/
312312
mappings?: CollectionMappings;
313+
/**
314+
* If true, reindex the collection
315+
*/
316+
reindexCollection?: boolean;
313317
/**
314318
* Elasticsearch index settings
315319
*/

0 commit comments

Comments
 (0)