Commit 8e54044f authored by anton's avatar anton

Add index/update for shell

parent fdb86a25
Pipeline #65072 passed with stages
in 1 minute and 55 seconds
......@@ -2,14 +2,30 @@
const
config = require('config'),
SearchIndex = require('mbjs-generic-api/src/lib/search-index')
{ ObjectUtil } = require('mbjs-utils'),
{ MongoDB } = require('mbjs-persistence'),
SearchIndex = require('mbjs-generic-api/src/lib/search-index'),
searchIndexMappings = require('../../src/search-index-mappings')
const main = async function () {
const [node, cmd, index] = process.argv
const [node, cmd, index, force] = process.argv
process.stdout.write(`${node} ${cmd}\n`)
process.stdout.write(`Updating index ${index}...\n`)
// const index = new SearchIndex(index)
const searchIndex = new SearchIndex(index, searchIndexMappings[index])
await searchIndex.ensure(!!force)
let count = 0
const client = new MongoDB(ObjectUtil.merge({name: index, logger: console}, config.get('resources.mongodb')), 'id')
const results = await client.find({})
for (const item of results) {
await searchIndex.index(item.id, ObjectUtil.merge({}, item, {_id: undefined}))
count++
if (count % 100 === 0) process.stdout.write(`Items ${count}\n`)
}
process.stdout.write(`Items ${count}\n`)
process.exit(0)
}
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment