Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit 205e171

Browse files
author
tkostuch
committed
add var catalog, update db7 create schema, update product schema
1 parent 89d3e92 commit 205e171

File tree

4 files changed

+3221
-2658
lines changed

4 files changed

+3221
-2658
lines changed

config/elastic.schema.product.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@
7676
"tax_class_id": {"type": "integer"},
7777
"gender": {"type": "integer"},
7878
"material": {"type": "integer"},
79-
"category_gear": {"type": "integer"}
79+
"category_gear": {"type": "integer"},
80+
"attributes_metadata": {
81+
"properties": {
82+
"id": {"type": "integer"},
83+
"attribute_id": {"type": "integer"},
84+
"default_frontend_label": {"type": "text"},
85+
"is_visible_on_front": {"type": "boolean"},
86+
"is_visible" : {"type": "boolean"},
87+
"frontend_input": {"type": "text"},
88+
"is_user_defined": {"type": "boolean"},
89+
"is_comparable": {"type": "boolean"},
90+
"attribute_code": {"type": "text"},
91+
"options": {
92+
"properties": {
93+
"value": {"type": "text"},
94+
"label": {"type": "text"}
95+
}
96+
}
97+
}
98+
}
8099
}
81100
}

scripts/db7.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,20 @@ program
5151
}, 1000)
5252
})
5353

54+
const asyncCreateIndex = (es, common, indexName, collectionName) => new Promise((resolve, reject) => {
55+
es.createIndex(common.db, indexName + '_' + collectionName, collectionName, (err) => {
56+
if (err) {
57+
reject(err)
58+
} else {
59+
resolve()
60+
}
61+
})
62+
})
63+
5464
program
5565
.command('new')
5666
.option('-i|--indexName <indexName>', 'name of the Elasticsearch index', config.elasticsearch.indices[0])
57-
.action((cmd) => { // TODO: add parallel processing
67+
.action(async (cmd) => { // TODO: add parallel processing
5868
if (!cmd.indexName) {
5969
console.error('error: indexName must be specified');
6070
process.exit(1);
@@ -63,19 +73,14 @@ program
6373
console.log('** Hello! I am going to create NEW ES index')
6474
const indexName = cmd.indexName
6575

66-
let waitingCounter = 0
67-
for (var indexTypeIterator in config.elasticsearch.indexTypes) {
68-
var collectionName = config.elasticsearch.indexTypes[indexTypeIterator]
69-
es.createIndex(common.db, indexName + '_' + collectionName, collectionName, (err) => {
70-
if (err) {
71-
console.log(err)
72-
}
73-
waitingCounter++
74-
})
76+
for (let collectionName of config.elasticsearch.indexTypes) {
77+
try {
78+
await asyncCreateIndex(es, common, indexName, collectionName)
79+
} catch (err) {
80+
console.log(JSON.stringify(err, null, 2))
81+
}
7582
}
76-
setInterval(() => {
77-
if (waitingCounter === config.elasticsearch.indexTypes.length) process.exit(0)
78-
}, 1000)
83+
process.exit(0)
7984
})
8085

8186
program

src/lib/elastic.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,19 @@ function loadSchema (entityType, apiVersion = '7.1') {
202202
return null
203203
}
204204
let schemaContent = jsonFile.readFileSync(rootSchemaPath)
205-
let elasticSchema = parseInt(apiVersion) < 6 ? schemaContent : Object.assign({}, { mappings: schemaContent });
205+
let elasticSchema = parseInt(apiVersion) < 6 ? schemaContent : Object.assign({}, {
206+
mappings: {
207+
[entityType]: schemaContent
208+
}
209+
});
206210
const extensionsPath = path.join(__dirname, '../../config/elastic.schema.' + entityType + '.extension.json');
207211
if (fs.existsSync(extensionsPath)) {
208212
schemaContent = jsonFile.readFileSync(extensionsPath)
209-
let elasticSchemaExtensions = parseInt(apiVersion) < 6 ? schemaContent : Object.assign({}, { mappings: schemaContent });
213+
let elasticSchemaExtensions = parseInt(apiVersion) < 6 ? schemaContent : Object.assign({}, {
214+
mappings: {
215+
[entityType]: schemaContent
216+
}
217+
});
210218
elasticSchema = _.merge(elasticSchema, elasticSchemaExtensions) // user extensions
211219
}
212220
return elasticSchema

0 commit comments

Comments
 (0)