@@ -54,7 +54,7 @@ function adjustQuery (esQuery, entityType, config) {
54
54
55
55
function getHits ( result ) {
56
56
if ( result . body ) { // differences between ES5 andd ES7
57
- return result . bodyc
57
+ return result . body
58
58
} else {
59
59
return result . hits . hits
60
60
}
@@ -136,7 +136,7 @@ function reIndex (db, fromIndexName, toIndexName, next) {
136
136
}
137
137
138
138
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 */
140
140
141
141
const step2 = ( ) => {
142
142
db . indices . delete ( {
@@ -182,28 +182,30 @@ function createIndex (db, indexName, collectionName, next) {
182
182
* Load the schema definition for particular entity type
183
183
* @param {String } entityType
184
184
*/
185
- function loadSchema ( entityType ) {
185
+ function loadSchema ( entityType , apiVersion = '7.1' ) {
186
186
const rootSchemaPath = path . join ( __dirname , '../../config/elastic.schema.' + entityType + '.json' )
187
187
if ( ! fs . existsSync ( rootSchemaPath ) ) {
188
188
return null
189
189
}
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 } ) ;
191
192
const extensionsPath = path . join ( __dirname , '../../config/elastic.schema.' + entityType + '.extension.json' ) ;
192
193
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 } ) ;
194
196
elasticSchema = _ . merge ( elasticSchema , elasticSchemaExtensions ) // user extensions
195
197
}
196
198
return elasticSchema
197
199
}
198
200
199
201
// this is deprecated just for ES 5.6
200
202
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 ') ;
207
209
208
210
db . indices . putMapping ( {
209
211
index : indexName ,
0 commit comments