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

Commit 5590e2e

Browse files
committed
Backward compatibility changes
1 parent 2548211 commit 5590e2e

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/lib/elastic.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function adjustQuery (esQuery, entityType, config) {
5454

5555
function getHits (result) {
5656
if (result.body) { // differences between ES5 andd ES7
57-
return result.bodyc
57+
return result.body
5858
} else {
5959
return result.hits.hits
6060
}
@@ -136,7 +136,7 @@ function reIndex (db, fromIndexName, toIndexName, next) {
136136
}
137137

138138
function createIndex (db, indexName, collectionName, next) {
139-
let indexSchema = collectionName ? loadSchema(collectionName) : loadSchema('index');
139+
let indexSchema = collectionName ? loadSchema(collectionName) : loadSchema('index', '5.6'); /** index schema is used only for 5.6 */
140140

141141
const step2 = () => {
142142
db.indices.delete({
@@ -182,28 +182,30 @@ function createIndex (db, indexName, collectionName, next) {
182182
* Load the schema definition for particular entity type
183183
* @param {String} entityType
184184
*/
185-
function loadSchema (entityType) {
185+
function loadSchema (entityType, apiVersion = '7.1') {
186186
const rootSchemaPath = path.join(__dirname, '../../config/elastic.schema.' + entityType + '.json')
187187
if (!fs.existsSync(rootSchemaPath)) {
188188
return null
189189
}
190-
let elasticSchema = Object.assign({}, { mappings: jsonFile.readFileSync(rootSchemaPath) });
190+
let schemaContent = jsonFile.readFileSync(rootSchemaPath)
191+
let elasticSchema = parseInt(apiVersion) < 6 ? schemaContent : Object.assign({}, { mappings: schemaContent });
191192
const extensionsPath = path.join(__dirname, '../../config/elastic.schema.' + entityType + '.extension.json');
192193
if (fs.existsSync(extensionsPath)) {
193-
let elasticSchemaExtensions = Object.assign({}, { mappings: jsonFile.readFileSync(extensionsPath) });
194+
schemaContent = jsonFile.readFileSync(extensionsPath)
195+
let elasticSchemaExtensions = parseInt(apiVersion) < 6 ? schemaContent : Object.assign({}, { mappings: schemaContent });
194196
elasticSchema = _.merge(elasticSchema, elasticSchemaExtensions) // user extensions
195197
}
196198
return elasticSchema
197199
}
198200

199201
// this is deprecated just for ES 5.6
200202
function putMappings (db, indexName, next) {
201-
let productSchema = loadSchema('product');
202-
let categorySchema = loadSchema('category');
203-
let taxruleSchema = loadSchema('taxrule');
204-
let attributeSchema = loadSchema('attribute');
205-
let pageSchema = loadSchema('page');
206-
let blockSchema = loadSchema('block');
203+
let productSchema = loadSchema('product', '5.6');
204+
let categorySchema = loadSchema('category', '5.6');
205+
let taxruleSchema = loadSchema('taxrule', '5.6');
206+
let attributeSchema = loadSchema('attribute', '5.6');
207+
let pageSchema = loadSchema('cms_page', '5.6');
208+
let blockSchema = loadSchema('cms_block', '5.6');
207209

208210
db.indices.putMapping({
209211
index: indexName,

0 commit comments

Comments
 (0)