forked from Language-Research-Technology/oni-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elastic-remote-indexer.js
60 lines (58 loc) · 2.06 KB
/
elastic-remote-indexer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// const {Client} = require('@elastic/elasticsearch');
const {Client} = require('@opensearch-project/opensearch');
const {Indexer} = require('./lib/Indexer-remote');
const configuration = require('./configuration.json');
const ocfl = require("@ocfl/ocfl-fs");
const fs = require("fs-extra");
const assert = require("assert");
const fetch = require("node-fetch");
let stop = undefined;
(async () => {
try {
//When debugging change stop to limit the indexing to a type integer
const args = process.argv;
if (args[2]) {
stop = parseInt(args[2]);
console.log('Indexer will stop at: ', stop);
}
} catch (e) {
console.log('Usage: node elastic-remote-indexer.js <STOP_AT_X>');
console.log('Wrong arguments, indexer will not stop');
}
// Init elastic client
console.log('Configuring elastic');
const client = new Client({
node: 'http://localhost:9200', //This is different from Oni since we are talking to it directly
});
// Bootstrap index
const elastic = configuration['api']['elastic'];
// Delete
try {
const res = await client.indices.exists({
index: elastic['index'] || 'items'
});
if (res['statusCode'] === 404) {
console.log('Creating Index')
await client.indices.create({
index: elastic['index'],
body: {
max_result_window: elastic['max_result_window'],
mappings: elastic['mappings']
}
});
}
} catch (e) {
console.log('index exist, continue');
}
// Do we need to skip some collections/objects?
let skipCollections = [];
const skipConfiguration = "./index.skip.json"
if (await fs.exists(skipConfiguration)) {
skipCollections = await fs.readJson(skipConfiguration, "utf-8");
assert(Array.isArray(skipCollections), `${skipConfiguration} not an array of strings, please fix.`);
}
// Create an Indexer and index collections
const indexer = new Indexer({configuration, client, stop});
await indexer.getOauthToken();
await indexer.findOcflObjects({memberOf: null, conformsTo: indexer.conformsToCollection, skip: skipCollections});
})();