check in create_index module, with tests

This commit is contained in:
2016-04-22 17:53:48 -07:00
parent 7e0f45019b
commit b78c5763ce
2 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
var schema = {
payload: { type: 'object', enabled: false },
priority: { type: 'short' },
process_timeout: { type: 'long' },
process_expiration: { type: 'date' },
created_at: { type: 'date' },
started_at: { type: 'date' },
completed_at: { type: 'date' },
attempts: { type: 'short' },
max_attempts: { type: 'short' },
status: { type: 'string', index: 'not_analyzed' },
output_content_type: { type: 'string', index: 'not_analyzed' },
output: { type: 'object', enabled: false }
};
export default function createIndex(client, indexName) {
const indexBody = {
mappings: {
_default_: {
properties: schema
}
}
};
return client.indices.exists({
index: indexName,
})
.then((exists) => {
if (!exists) {
return client.indices.create({
ignore: 400,
index: indexName,
body: indexBody
})
.then(() => true);
}
return exists;
});
}