allow index settings to be passed on index creation

This commit is contained in:
2016-06-28 18:28:53 -07:00
parent 1d4c45c5d9
commit 13a78d12cc

View File

@@ -22,10 +22,12 @@ const schema = {
} }
}; };
export default function createIndex(client, indexName, doctype = defaultSettings.DEFAULT_SETTING_DOCTYPE) { export default function createIndex(client, indexName, doctype = defaultSettings.DEFAULT_SETTING_DOCTYPE, settings = {}) {
const indexBody = { mappings : {} }; const indexBody = { mappings : {} };
indexBody.mappings[doctype] = { properties: schema }; indexBody.mappings[doctype] = { properties: schema };
const body = Object.assign({}, { settings }, indexBody);
return client.indices.exists({ return client.indices.exists({
index: indexName, index: indexName,
}) })
@@ -34,7 +36,7 @@ export default function createIndex(client, indexName, doctype = defaultSettings
return client.indices.create({ return client.indices.create({
ignore: 400, ignore: 400,
index: indexName, index: indexName,
body: indexBody body: body
}) })
.then(() => true); .then(() => true);
} }