diff --git a/lib/index.js b/lib/index.js index 070440e..298f401 100644 --- a/lib/index.js +++ b/lib/index.js @@ -157,7 +157,7 @@ function createMapping(settings, callback, version) { if (version === 7) { // Keep shards settings like the previous versions if (!createIndexOpts.body.settings) { - createIndexOpts.body = { settings: {} }; + createIndexOpts.body = { settings }; } createIndexOpts.body.settings.number_of_shards = settings.number_of_shards || 5; diff --git a/lib/mapping.js b/lib/mapping.js index bcf5a5f..3df0aba 100644 --- a/lib/mapping.js +++ b/lib/mapping.js @@ -12,7 +12,7 @@ module.exports.generate = generate; * @param {integer} [version] * @returns {Object} */ -function generate(schema, version) { +function generate(schema, version, isRoot = true) { const mapping = {}; const typeKey = getTypeKey(schema); const explicit = hasExplicit(schema, typeKey); @@ -20,7 +20,7 @@ function generate(schema, version) { Object.keys(schema.paths).forEach(name => { // ignore _id because is used as index - if (name === '_id') { + if (name === '_id' && isRoot) { return; } @@ -67,7 +67,7 @@ function generate(schema, version) { if (!{}.hasOwnProperty.call(options, 'es_value') || !options.es_type) { if (isEmbedded(type)) { current.type = 'object'; - current.properties = generate(path.schema, version); + current.properties = generate(path.schema, version, false); } if (defaultTypes[type]) { current.type = defaultTypes[type];