-
-
Save Aschen/67ee985b2445273edea6b172414e9bfe to your computer and use it in GitHub Desktop.
Code for PR admin-console#432
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Bluebird = require('bluebird') | |
const Kuzzle = require('kuzzle-sdk'); | |
const kuzzle = new Kuzzle('localhost', (err, resp) => { | |
const documents = [ | |
['gordon', 'freeman', 'blackmesa', 32], | |
['alyx', 'vance', 'city17', 26], | |
['isaac', 'kleiner', 'blackmesa', 46], | |
['eli', 'vance', 'blackmesa', 53], | |
['barney', 'calhoun', 'city17', 36], | |
['arne', 'magnusson', 'whiteforest', 54], | |
['wallace', 'breen', 'city17', 48] | |
]; | |
const mapping = { | |
properties: { | |
firstname: { type: "text" }, | |
lastname: { type: "text" }, | |
city: { type: "text" }, | |
age: { type: "integer" } | |
} | |
} | |
kuzzle | |
.createIndexPromise('my-index') | |
.catch(error => console.log(error)) | |
.then(() => kuzzle.collection('my-collection', 'my-index').createPromise(mapping)) | |
.catch(error => console.log(error)) | |
.then(() => { | |
const promises = documents.map(([firstname, lastname, city, age]) => { | |
const document = { | |
firstname, lastname, city, age | |
}; | |
console.log(document) | |
return kuzzle | |
.collection('my-collection', 'my-index') | |
.createDocumentPromise(`${firstname}-${lastname}`, document) | |
}) | |
return Bluebird.all(promises); | |
}) | |
.then(response => console.log(response)) | |
.catch(error => console.log(error)) | |
.finally(() => kuzzle.disconnect()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment