check in create_index module, with tests
This commit is contained in:
39
src/helpers/create_index.js
Normal file
39
src/helpers/create_index.js
Normal 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;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user