-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathimport.js
More file actions
29 lines (26 loc) · 840 Bytes
/
Copy pathimport.js
File metadata and controls
29 lines (26 loc) · 840 Bytes
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
'use strict'
// This is just an example app to import the files to Vue Storefront default index
const elasticsearch = require('elasticsearch');
const fs = require('fs');
const client = new elasticsearch.Client({
hosts: [ 'http://localhost:9200'],
apiVersion: '5.6'
});
const fileName = process.argv[2]
const entityType = process.argv[3]
const indexName = process.argv[4]
if (!fileName || !entityType) {
console.error('Please run `node import.js [fileName] [product|attribute|category] [indexName]')
}
const records = JSON.parse(fs.readFileSync(fileName))
for (const record of records) {
console.log(`Importing ${entityType}`, record)
client.index({
index: indexName,
id: record.id,
type: entityType,
body: record
}, function(err, resp, status) {
console.log(resp);
});
}