@vegan-friendly/strapi-plugin-elasticsearch 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/src/components/SubNavigation/index.d.ts +1 -1
- package/dist/admin/src/components/SubNavigation/index.js +1 -1
- package/dist/admin/src/pages/ConfigureCollection/index.js +13 -5
- package/dist/admin/src/pages/ViewIndexingRunLog/index.js +9 -9
- package/dist/admin/src/utils/axiosInstance.js +3 -5
- package/dist/package.json +3 -3
- package/dist/server/bootstrap.js +1 -1
- package/dist/server/index.d.ts +3 -3
- package/dist/server/services/es-interface.js +5 -4
- package/dist/server/services/helper.d.ts +3 -3
- package/dist/server/services/helper.js +17 -11
- package/dist/server/services/index.d.ts +3 -3
- package/dist/server/services/virtual-collections-indexer.js +33 -27
- package/dist/server/types/esInterface.type.d.ts +4 -2
- package/dist/server/types/virtual-collections.type.d.ts +22 -9
- package/package.json +4 -4
@@ -10,7 +10,7 @@ const design_system_1 = require("@strapi/design-system");
|
|
10
10
|
const design_system_2 = require("@strapi/design-system");
|
11
11
|
const react_router_dom_1 = require("react-router-dom");
|
12
12
|
const pluginId_1 = __importDefault(require("../../pluginId"));
|
13
|
-
const SubNavigation = ({ activeUrl }) => {
|
13
|
+
const SubNavigation = ({ activeUrl = null }) => {
|
14
14
|
const links = [
|
15
15
|
{
|
16
16
|
id: 1,
|
@@ -110,7 +110,7 @@ const ConfigureCollection = () => {
|
|
110
110
|
const updateCollectionsConfig = ({ index, config }) => {
|
111
111
|
setCollectionConfig({
|
112
112
|
collectionName: collectionConfig.collectionName,
|
113
|
-
attributes: collectionConfig.attributes.map((e, idx) => index === idx ? config : e)
|
113
|
+
attributes: collectionConfig.attributes.map((e, idx) => (index === idx ? config : e)),
|
114
114
|
});
|
115
115
|
};
|
116
116
|
const saveCollectionConfig = () => {
|
@@ -125,12 +125,16 @@ const ConfigureCollection = () => {
|
|
125
125
|
saveConfigForCollection(collectionConfig.collectionName, data)
|
126
126
|
.then((resp) => {
|
127
127
|
toggleNotification({
|
128
|
-
type:
|
128
|
+
type: 'success',
|
129
|
+
message: 'The collection configuration is saved.',
|
130
|
+
timeout: 5000,
|
129
131
|
});
|
130
132
|
})
|
131
133
|
.catch((err) => {
|
132
134
|
toggleNotification({
|
133
|
-
type:
|
135
|
+
type: 'warning',
|
136
|
+
message: err.message || 'An error was encountered.',
|
137
|
+
timeout: 5000,
|
134
138
|
});
|
135
139
|
console.log(err);
|
136
140
|
})
|
@@ -147,7 +151,9 @@ const ConfigureCollection = () => {
|
|
147
151
|
.then((resp) => {
|
148
152
|
if (Object.keys(resp).length === 0) {
|
149
153
|
toggleNotification({
|
150
|
-
type:
|
154
|
+
type: 'warning',
|
155
|
+
message: 'No collection with the selected name exists.',
|
156
|
+
timeout: 5000,
|
151
157
|
});
|
152
158
|
}
|
153
159
|
else {
|
@@ -162,7 +168,9 @@ const ConfigureCollection = () => {
|
|
162
168
|
})
|
163
169
|
.catch((err) => {
|
164
170
|
toggleNotification({
|
165
|
-
type:
|
171
|
+
type: 'warning',
|
172
|
+
message: err.message || 'An error was encountered.',
|
173
|
+
timeout: 5000,
|
166
174
|
});
|
167
175
|
console.log(err);
|
168
176
|
});
|
@@ -51,7 +51,8 @@ const design_system_2 = require("@strapi/design-system");
|
|
51
51
|
const design_system_3 = require("@strapi/design-system");
|
52
52
|
const helper_plugin_1 = require("@strapi/helper-plugin");
|
53
53
|
const loadRecentIndexingRuns = () => {
|
54
|
-
return axiosInstance_1.default
|
54
|
+
return axiosInstance_1.default
|
55
|
+
.get(apiUrls_1.apiFetchRecentIndexingRunLog)
|
55
56
|
.then((resp) => resp.data)
|
56
57
|
.then((data) => {
|
57
58
|
return data;
|
@@ -71,17 +72,17 @@ const formattedDate = (dateString) => {
|
|
71
72
|
const parts = dateTimeFormat.formatToParts(date);
|
72
73
|
let formattedDate = '';
|
73
74
|
parts.forEach((part) => {
|
74
|
-
if (part.type ===
|
75
|
+
if (part.type === 'weekday')
|
75
76
|
formattedDate += `${part.value}, `;
|
76
|
-
if (part.type ===
|
77
|
+
if (part.type === 'day')
|
77
78
|
formattedDate += `${part.value}/`;
|
78
|
-
if (part.type ===
|
79
|
+
if (part.type === 'month')
|
79
80
|
formattedDate += `${part.value}/`;
|
80
|
-
if (part.type ===
|
81
|
+
if (part.type === 'year')
|
81
82
|
formattedDate += `${part.value} `;
|
82
|
-
if (part.type ===
|
83
|
+
if (part.type === 'hour')
|
83
84
|
formattedDate += `${part.value}:`;
|
84
|
-
if (part.type ===
|
85
|
+
if (part.type === 'minute')
|
85
86
|
formattedDate += `${part.value}`;
|
86
87
|
});
|
87
88
|
return formattedDate;
|
@@ -89,8 +90,7 @@ const formattedDate = (dateString) => {
|
|
89
90
|
const ViewIndexingRunLog = () => {
|
90
91
|
const [logTable, setLogTable] = (0, react_1.useState)(null);
|
91
92
|
(0, react_1.useEffect)(() => {
|
92
|
-
loadRecentIndexingRuns()
|
93
|
-
.then(setLogTable);
|
93
|
+
loadRecentIndexingRuns().then(setLogTable);
|
94
94
|
}, []);
|
95
95
|
if (logTable === null)
|
96
96
|
return react_1.default.createElement(helper_plugin_1.LoadingIndicatorPage, null);
|
@@ -12,11 +12,9 @@ const instance = axios_1.default.create({
|
|
12
12
|
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
|
13
13
|
});
|
14
14
|
instance.interceptors.request.use(async (config) => {
|
15
|
-
config.headers
|
16
|
-
|
17
|
-
|
18
|
-
'Content-Type': 'application/json',
|
19
|
-
};
|
15
|
+
config.headers.set('Authorization', `Bearer ${helper_plugin_1.auth.getToken()}`);
|
16
|
+
config.headers.set('Accept', 'application/json');
|
17
|
+
config.headers.set('Content-Type', 'application/json');
|
20
18
|
return config;
|
21
19
|
}, error => {
|
22
20
|
Promise.reject(error);
|
package/dist/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vegan-friendly/strapi-plugin-elasticsearch",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.2",
|
4
4
|
"description": "A Strapi plugin to enable using Elasticsearch with Strapi CMS.",
|
5
5
|
"homepage": "https://github.com/vegan-friendly/strapi-plugin-elasticsearch",
|
6
6
|
"strapi": {
|
@@ -37,8 +37,8 @@
|
|
37
37
|
"dependencies": {
|
38
38
|
"@elastic/elasticsearch": "^8.9.0",
|
39
39
|
"@strapi/design-system": "^1.19.0",
|
40
|
-
"
|
41
|
-
"
|
40
|
+
"humanize-duration": "^3.32.1",
|
41
|
+
"markdown-to-txt": "^2.0.1"
|
42
42
|
},
|
43
43
|
"peerDependencies": {
|
44
44
|
"@strapi/strapi": "^4.0.0"
|
package/dist/server/bootstrap.js
CHANGED
@@ -12,7 +12,7 @@ exports.default = async ({ strapi }) => {
|
|
12
12
|
await configureIndexingService.initializeStrapiElasticsearch();
|
13
13
|
if (!Object.keys(pluginConfig).includes('indexingCronSchedule'))
|
14
14
|
console.warn('The plugin strapi-plugin-elasticsearch is enabled but the indexingCronSchedule is not configured.');
|
15
|
-
|
15
|
+
if (!Object.keys(pluginConfig).includes('searchConnector'))
|
16
16
|
console.warn('The plugin strapi-plugin-elasticsearch is enabled but the searchConnector is not configured.');
|
17
17
|
else {
|
18
18
|
const connector = pluginConfig['searchConnector'];
|
package/dist/server/index.d.ts
CHANGED
@@ -185,9 +185,9 @@ declare const _default: {
|
|
185
185
|
collectionName: any;
|
186
186
|
itemId: any;
|
187
187
|
}): string;
|
188
|
-
getCurrentIndexName(): Promise<string>;
|
189
|
-
getIncrementedIndexName(): Promise<string>;
|
190
|
-
storeCurrentIndexName(indexName: any): Promise<void>;
|
188
|
+
getCurrentIndexName(indexPrefix?: string): Promise<string>;
|
189
|
+
getIncrementedIndexName(indexPrefix?: string): Promise<string>;
|
190
|
+
storeCurrentIndexName(indexName: any, indexPrefix?: string): Promise<void>;
|
191
191
|
modifySubfieldsConfigForExtractor(collectionConfig: any): any;
|
192
192
|
extractDataToIndex({ collectionName, data, collectionConfig }: {
|
193
193
|
collectionName: any;
|
@@ -29,13 +29,14 @@ exports.default = ({ strapi }) => ({
|
|
29
29
|
throw err;
|
30
30
|
}
|
31
31
|
},
|
32
|
-
async createIndex(indexName) {
|
32
|
+
async createIndex(indexName, mappings) {
|
33
33
|
try {
|
34
34
|
const exists = await client.indices.exists({ index: indexName });
|
35
35
|
if (!exists) {
|
36
36
|
console.log('strapi-plugin-elasticsearch : Search index ', indexName, ' does not exist. Creating index.');
|
37
37
|
await client.indices.create({
|
38
38
|
index: indexName,
|
39
|
+
mappings: mappings ?? undefined,
|
39
40
|
});
|
40
41
|
}
|
41
42
|
}
|
@@ -67,10 +68,10 @@ exports.default = ({ strapi }) => ({
|
|
67
68
|
}
|
68
69
|
}
|
69
70
|
},
|
70
|
-
async attachAliasToIndex(indexName) {
|
71
|
+
async attachAliasToIndex(indexName, optionalAliasName, mappings) {
|
71
72
|
try {
|
72
73
|
const pluginConfig = await strapi.config.get('plugin.elasticsearch');
|
73
|
-
const aliasName = pluginConfig.indexAliasName;
|
74
|
+
const aliasName = optionalAliasName ? optionalAliasName : pluginConfig.indexAliasName;
|
74
75
|
const aliasExists = await client.indices.existsAlias({ name: aliasName });
|
75
76
|
if (aliasExists) {
|
76
77
|
console.log('strapi-plugin-elasticsearch : Alias with this name already exists, removing it.');
|
@@ -78,7 +79,7 @@ exports.default = ({ strapi }) => ({
|
|
78
79
|
}
|
79
80
|
const indexExists = await client.indices.exists({ index: indexName });
|
80
81
|
if (!indexExists)
|
81
|
-
await this.createIndex(indexName);
|
82
|
+
await this.createIndex(indexName, mappings);
|
82
83
|
console.log('strapi-plugin-elasticsearch : Attaching the alias ', aliasName, ' to index : ', indexName);
|
83
84
|
await client.indices.putAlias({ index: indexName, name: aliasName });
|
84
85
|
}
|
@@ -22,9 +22,9 @@ declare const _default: ({ strapi }: {
|
|
22
22
|
collectionName: any;
|
23
23
|
itemId: any;
|
24
24
|
}): string;
|
25
|
-
getCurrentIndexName(): Promise<string>;
|
26
|
-
getIncrementedIndexName(): Promise<string>;
|
27
|
-
storeCurrentIndexName(indexName: any): Promise<void>;
|
25
|
+
getCurrentIndexName(indexPrefix?: string): Promise<string>;
|
26
|
+
getIncrementedIndexName(indexPrefix?: string): Promise<string>;
|
27
|
+
storeCurrentIndexName(indexName: any, indexPrefix?: string): Promise<void>;
|
28
28
|
modifySubfieldsConfigForExtractor(collectionConfig: any): any;
|
29
29
|
extractDataToIndex({ collectionName, data, collectionConfig }: {
|
30
30
|
collectionName: any;
|
@@ -6,6 +6,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
7
7
|
const fp_1 = require("lodash/fp");
|
8
8
|
const transform_content_1 = __importDefault(require("./transform-content"));
|
9
|
+
const defaultIndexPrefix = 'strapi-plugin-elasticsearch-index';
|
9
10
|
const getPluginStore = () => {
|
10
11
|
return strapi.store({
|
11
12
|
environment: '',
|
@@ -14,7 +15,7 @@ const getPluginStore = () => {
|
|
14
15
|
});
|
15
16
|
};
|
16
17
|
const getModelPopulationAttributes = (model) => {
|
17
|
-
if (model.uid ===
|
18
|
+
if (model.uid === 'plugin::upload.file') {
|
18
19
|
const { related, ...attributes } = model.attributes;
|
19
20
|
return attributes;
|
20
21
|
}
|
@@ -192,34 +193,39 @@ exports.default = ({ strapi }) => ({
|
|
192
193
|
getIndexItemId({ collectionName, itemId }) {
|
193
194
|
return collectionName + '::' + itemId;
|
194
195
|
},
|
195
|
-
async getCurrentIndexName() {
|
196
|
+
async getCurrentIndexName(indexPrefix = defaultIndexPrefix) {
|
196
197
|
const pluginStore = getPluginStore();
|
197
198
|
const settings = (await pluginStore.get({ key: 'configsettings' }));
|
198
|
-
let indexName = '
|
199
|
+
let indexName = indexPrefix + '_000001';
|
199
200
|
if (settings) {
|
200
201
|
const objSettings = JSON.parse(settings);
|
201
202
|
if (Object.keys(objSettings).includes('indexConfig')) {
|
202
203
|
const idxConfig = objSettings['indexConfig'];
|
203
|
-
|
204
|
+
if (idxConfig[indexPrefix]) {
|
205
|
+
indexName = idxConfig[indexPrefix];
|
206
|
+
}
|
204
207
|
}
|
205
208
|
}
|
206
209
|
return indexName;
|
207
210
|
},
|
208
|
-
async getIncrementedIndexName() {
|
209
|
-
const currentIndexName = await this.getCurrentIndexName();
|
210
|
-
const number = parseInt(currentIndexName.split('
|
211
|
-
return '
|
211
|
+
async getIncrementedIndexName(indexPrefix = defaultIndexPrefix) {
|
212
|
+
const currentIndexName = await this.getCurrentIndexName(indexPrefix);
|
213
|
+
const number = parseInt(currentIndexName.split(indexPrefix + '_')[1]);
|
214
|
+
return indexPrefix + '_' + String(number + 1).padStart(6, '0');
|
212
215
|
},
|
213
|
-
async storeCurrentIndexName(indexName) {
|
216
|
+
async storeCurrentIndexName(indexName, indexPrefix = defaultIndexPrefix) {
|
214
217
|
const pluginStore = getPluginStore();
|
215
218
|
const settings = (await pluginStore.get({ key: 'configsettings' }));
|
216
219
|
if (settings) {
|
217
220
|
const objSettings = JSON.parse(settings);
|
218
|
-
objSettings['indexConfig'] = {
|
221
|
+
objSettings['indexConfig'] = {
|
222
|
+
...objSettings['indexConfig'],
|
223
|
+
[indexPrefix]: indexName,
|
224
|
+
};
|
219
225
|
await pluginStore.set({ key: 'configsettings', value: JSON.stringify(objSettings) });
|
220
226
|
}
|
221
227
|
else {
|
222
|
-
const newSettings = JSON.stringify({ indexConfig: {
|
228
|
+
const newSettings = JSON.stringify({ indexConfig: { [indexPrefix]: indexName } });
|
223
229
|
await pluginStore.set({ key: 'configsettings', value: newSettings });
|
224
230
|
}
|
225
231
|
},
|
@@ -81,9 +81,9 @@ declare const _default: {
|
|
81
81
|
collectionName: any;
|
82
82
|
itemId: any;
|
83
83
|
}): string;
|
84
|
-
getCurrentIndexName(): Promise<string>;
|
85
|
-
getIncrementedIndexName(): Promise<string>;
|
86
|
-
storeCurrentIndexName(indexName: any): Promise<void>;
|
84
|
+
getCurrentIndexName(indexPrefix?: string): Promise<string>;
|
85
|
+
getIncrementedIndexName(indexPrefix?: string): Promise<string>;
|
86
|
+
storeCurrentIndexName(indexName: any, indexPrefix?: string): Promise<void>;
|
87
87
|
modifySubfieldsConfigForExtractor(collectionConfig: any): any;
|
88
88
|
extractDataToIndex({ collectionName, data, collectionConfig }: {
|
89
89
|
collectionName: any;
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
const
|
6
|
+
const humanize_duration_1 = __importDefault(require("humanize-duration"));
|
7
7
|
/**
|
8
8
|
* Service to handle indexing of virtual collections
|
9
9
|
*/
|
@@ -27,44 +27,44 @@ exports.default = ({ strapi }) => {
|
|
27
27
|
strapi.log.warn(`No data extracted for ${collectionName} with ID ${itemId}`);
|
28
28
|
return null;
|
29
29
|
}
|
30
|
-
const
|
31
|
-
const
|
32
|
-
const esService = getElasticsearchService();
|
30
|
+
const itemData = results[0];
|
31
|
+
const esInterface = getElasticsearchService();
|
33
32
|
const helper = getHelperService();
|
34
33
|
const indexItemId = helper.getIndexItemId(collectionName, itemId);
|
35
|
-
|
34
|
+
const indexName = await helper.getCurrentIndexName();
|
35
|
+
await esInterface.indexDataToSpecificIndex({ itemId: indexItemId, itemData }, indexName);
|
36
36
|
strapi.log.debug(`Indexed virtual item: ${collectionName}:${itemId}`);
|
37
|
-
return
|
37
|
+
return itemData;
|
38
38
|
}
|
39
39
|
catch (error) {
|
40
40
|
strapi.log.error(`Error indexing ${collectionName}:${itemId}: ${error?.message}`);
|
41
41
|
throw error;
|
42
42
|
}
|
43
43
|
},
|
44
|
-
async reindexAll(
|
44
|
+
async reindexAll() {
|
45
|
+
const timestamp = Date.now();
|
45
46
|
const registry = getRegistryService();
|
46
47
|
const collections = registry.getAll();
|
47
48
|
let totalIndexed = 0;
|
48
49
|
for (const collection of collections) {
|
49
|
-
totalIndexed += await this.reindex(collection
|
50
|
+
totalIndexed += await this.reindex(collection);
|
50
51
|
}
|
51
|
-
|
52
|
+
strapi.log.info(`strapi-plugin-elasticsearch : Reindexed ${totalIndexed} items across all ${collections.length} virtual collections. took ${(0, humanize_duration_1.default)(Date.now() - timestamp)} `);
|
52
53
|
return totalIndexed;
|
53
54
|
},
|
54
55
|
/**
|
55
56
|
* Reindex all items in a virtual collection
|
56
57
|
*/
|
57
|
-
async reindex(
|
58
|
-
const
|
59
|
-
const
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
async reindex(collection) {
|
59
|
+
const collectionName = collection.collectionName;
|
60
|
+
const indexAlias = collection.indexAlias;
|
61
|
+
const helper = getHelperService();
|
62
|
+
const oldIndexName = await helper.getCurrentIndexName(indexAlias);
|
63
|
+
const newIndexName = await helper.getIncrementedIndexName(indexAlias);
|
64
|
+
let timestamp = Date.now();
|
64
65
|
try {
|
65
|
-
const
|
66
|
-
|
67
|
-
// await esService.createIndex(tempIndexName);
|
66
|
+
const esInterface = getElasticsearchService();
|
67
|
+
await esInterface.createIndex(newIndexName, collection.mappings);
|
68
68
|
let page = 0;
|
69
69
|
let hasMoreData = true;
|
70
70
|
let totalIndexed = 0;
|
@@ -75,22 +75,28 @@ exports.default = ({ strapi }) => {
|
|
75
75
|
break;
|
76
76
|
}
|
77
77
|
const operations = [];
|
78
|
-
for (const
|
79
|
-
const itemId = helper.getIndexItemId({ collectionName, itemId:
|
80
|
-
const itemData = collection.mapToIndex ? item : item;
|
78
|
+
for (const itemData of pageData) {
|
79
|
+
const itemId = helper.getIndexItemId({ collectionName, itemId: itemData.id });
|
81
80
|
operations.push({ itemId, itemData });
|
82
81
|
}
|
83
82
|
if (operations.length > 0) {
|
84
|
-
await Promise.all(operations.map((op) =>
|
83
|
+
await Promise.all(operations.map((op) => esInterface.indexDataToSpecificIndex(op, newIndexName)));
|
85
84
|
}
|
86
85
|
totalIndexed += pageData.length;
|
87
86
|
page++;
|
88
87
|
}
|
89
|
-
strapi.log.info(`Reindexed ${totalIndexed} items for virtual collection: ${collectionName}. took ${(0,
|
88
|
+
strapi.log.info(`Reindexed ${totalIndexed} items for virtual collection: ${collectionName}. took ${(0, humanize_duration_1.default)(Date.now() - timestamp)}. now updating alias.`);
|
89
|
+
timestamp = Date.now();
|
90
|
+
await esInterface.attachAliasToIndex(newIndexName, indexAlias, collection.mappings);
|
91
|
+
strapi.log.info(`Done attachAliasToIndex alias ${indexAlias} to index ${newIndexName}. took ${(0, humanize_duration_1.default)(Date.now() - timestamp)}`);
|
92
|
+
timestamp = Date.now();
|
93
|
+
await helper.storeCurrentIndexName(newIndexName, indexAlias);
|
94
|
+
await esInterface.deleteIndex(oldIndexName);
|
95
|
+
strapi.log.info(`Done deleting ${oldIndexName}. took ${(0, humanize_duration_1.default)(Date.now() - timestamp)}`);
|
90
96
|
return totalIndexed;
|
91
97
|
}
|
92
98
|
catch (error) {
|
93
|
-
strapi.log.error(`Error reindexing ${collectionName}: ${error?.message} after ${(0,
|
99
|
+
strapi.log.error(`Error reindexing ${collectionName}: ${error?.message} after ${(0, humanize_duration_1.default)(Date.now() - timestamp)}`);
|
94
100
|
throw error;
|
95
101
|
}
|
96
102
|
},
|
@@ -125,8 +131,8 @@ exports.default = ({ strapi }) => {
|
|
125
131
|
throw new Error(`Virtual collection not found: ${collectionName}`);
|
126
132
|
}
|
127
133
|
try {
|
128
|
-
const
|
129
|
-
await
|
134
|
+
const esInterface = getElasticsearchService();
|
135
|
+
await esInterface.removeItemFromIndex({ itemId });
|
130
136
|
strapi.log.debug(`Deleted indexed item: ${collectionName}:${itemId}`);
|
131
137
|
return true;
|
132
138
|
}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { MappingTypeMapping } from '@elastic/elasticsearch/lib/api/types';
|
1
2
|
export interface EsInterfaceService {
|
2
3
|
/**
|
3
4
|
* Initializes the search engine connection.
|
@@ -15,7 +16,7 @@ export interface EsInterfaceService {
|
|
15
16
|
* @param indexName - The name of the index to create.
|
16
17
|
* @returns A promise that resolves when the index is created.
|
17
18
|
*/
|
18
|
-
createIndex(indexName: string): Promise<void>;
|
19
|
+
createIndex(indexName: string, mappings?: MappingTypeMapping): Promise<void>;
|
19
20
|
/**
|
20
21
|
* Deletes an index from the search engine.
|
21
22
|
* @param indexName - The name of the index to delete.
|
@@ -25,9 +26,10 @@ export interface EsInterfaceService {
|
|
25
26
|
/**
|
26
27
|
* Attaches an alias to a specific index.
|
27
28
|
* @param indexName - The index to which the alias should be attached.
|
29
|
+
* @param aliasName - Alias to attach. If not provided, alias from configuration 'indexAliasName' will be used.
|
28
30
|
* @returns A promise that resolves when the alias is set.
|
29
31
|
*/
|
30
|
-
attachAliasToIndex(indexName: string): Promise<void>;
|
32
|
+
attachAliasToIndex(indexName: string, aliasName?: string, mappings?: MappingTypeMapping): Promise<void>;
|
31
33
|
/**
|
32
34
|
* Checks the connection status of the search engine.
|
33
35
|
* @returns A promise that resolves with the connection status.
|
@@ -1,5 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import { MappingTypeMapping } from '@elastic/elasticsearch/lib/api/types';
|
2
|
+
export type VirtualCollectionConfig<T extends StrapiEntity> = {
|
3
|
+
/**
|
4
|
+
* The alias of the latest index in Elasticsearch.
|
5
|
+
* It also serves as a prefix to actual indexes created in Elasticsearch.
|
6
|
+
* The actuall index name will be the `${indexNameBase}_${ind}`, e.g `restaurants_000001` and so on.
|
7
|
+
* and the alias will be the `indexNameBase`.
|
8
|
+
*/
|
9
|
+
indexAlias: string;
|
3
10
|
collectionName: string;
|
4
11
|
extractData: (page: number, pageSize?: number) => Promise<T[]>;
|
5
12
|
extractById: (ids: number[]) => Promise<T[]>;
|
@@ -7,7 +14,11 @@ export type VirtualCollectionConfig<T extends {}> = {
|
|
7
14
|
collection: string;
|
8
15
|
getIdsToReindex: (result: any) => Promise<number[]>;
|
9
16
|
}>;
|
10
|
-
|
17
|
+
/**
|
18
|
+
* Optional schema to be sent to Elasticsearch when creating the index.
|
19
|
+
* If you don't include this, ElasticSearch will automatically create a schema for you.
|
20
|
+
*/
|
21
|
+
mappings?: MappingTypeMapping;
|
11
22
|
};
|
12
23
|
export interface VirtualCollectionsRegistryService {
|
13
24
|
/**
|
@@ -15,7 +26,7 @@ export interface VirtualCollectionsRegistryService {
|
|
15
26
|
* @param config - The configuration for the virtual collection
|
16
27
|
* @returns The current instance of the registry
|
17
28
|
*/
|
18
|
-
register<T extends
|
29
|
+
register<T extends StrapiEntity>(config: VirtualCollectionConfig<T>): this;
|
19
30
|
/**
|
20
31
|
* get all registered virtual collections
|
21
32
|
* @returns An array of all registered virtual collections
|
@@ -24,6 +35,10 @@ export interface VirtualCollectionsRegistryService {
|
|
24
35
|
get(collectionName: string): VirtualCollectionConfig<any> | null;
|
25
36
|
findTriggersByCollection(collectionUID: string): Array<VirtualCollectionConfig<any>>;
|
26
37
|
}
|
38
|
+
export type StrapiEntity = {
|
39
|
+
id: number;
|
40
|
+
[key: string]: any;
|
41
|
+
};
|
27
42
|
export interface VirtualCollectionsIndexerService {
|
28
43
|
/**
|
29
44
|
* Index a single item from a virtual collection.
|
@@ -33,15 +48,13 @@ export interface VirtualCollectionsIndexerService {
|
|
33
48
|
indexItem(collectionName: string, itemId: number): Promise<any>;
|
34
49
|
/**
|
35
50
|
* Reindex all items in a virtual collection index.
|
36
|
-
* @param indexName - The target index name.
|
37
51
|
*/
|
38
|
-
reindexAll(
|
52
|
+
reindexAll(): Promise<any>;
|
39
53
|
/**
|
40
54
|
* Reindex all items in a virtual collection.
|
41
|
-
* @param
|
42
|
-
* @param indexName - The target index name.
|
55
|
+
* @param collection - The virtual collection config.
|
43
56
|
*/
|
44
|
-
reindex
|
57
|
+
reindex<T extends StrapiEntity>(collection: VirtualCollectionConfig<T>): Promise<any>;
|
45
58
|
/**
|
46
59
|
* Handle a trigger event from a collection.
|
47
60
|
* @param event - The trigger event.
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vegan-friendly/strapi-plugin-elasticsearch",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.2",
|
4
4
|
"description": "A Strapi plugin to enable using Elasticsearch with Strapi CMS.",
|
5
5
|
"homepage": "https://github.com/vegan-friendly/strapi-plugin-elasticsearch",
|
6
6
|
"strapi": {
|
@@ -37,8 +37,8 @@
|
|
37
37
|
"dependencies": {
|
38
38
|
"@elastic/elasticsearch": "^8.9.0",
|
39
39
|
"@strapi/design-system": "^1.19.0",
|
40
|
-
"
|
41
|
-
"
|
40
|
+
"humanize-duration": "^3.32.1",
|
41
|
+
"markdown-to-txt": "^2.0.1"
|
42
42
|
},
|
43
43
|
"peerDependencies": {
|
44
44
|
"@strapi/strapi": "^4.0.0"
|
@@ -61,4 +61,4 @@
|
|
61
61
|
"ts-node": "^10.9.2",
|
62
62
|
"typescript": "^5.8.3"
|
63
63
|
}
|
64
|
-
}
|
64
|
+
}
|