Skip to content

Instantly share code, notes, and snippets.

@Aschen
Created August 21, 2018 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aschen/67ee985b2445273edea6b172414e9bfe to your computer and use it in GitHub Desktop.
Save Aschen/67ee985b2445273edea6b172414e9bfe to your computer and use it in GitHub Desktop.
Code for PR admin-console#432
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