Skip to content

Instantly share code, notes, and snippets.

@Aschen
Created November 28, 2019 03:50
Show Gist options
  • Select an option

  • Save Aschen/e4467cd2e0d40d3d15e1a74d770079b4 to your computer and use it in GitHub Desktop.

Select an option

Save Aschen/e4467cd2e0d40d3d15e1a74d770079b4 to your computer and use it in GitHub Desktop.
Create Kuzzle collection with mappings
const {
Kuzzle,
WebSocket
} = require('kuzzle-sdk')
const kuzzle = new Kuzzle(new WebSocket("localhost"))
kuzzle.on('networkError', error => console.error(error));
(async () => {
try {
await kuzzle.connect();
const mappings = {
"dynamic_templates": [
{
"strings": {
"path_match": "trackers.*",
"match_mapping_type": "string",
"mapping": {
"type": "keyword"
}
}
},
{
"integers": {
"path_match": "trackers.symptom.*",
"match_mapping_type": "long",
"mapping": {
"type": "byte"
}
}
}
],
"properties": {
"date": {
"type": "date",
"format": "strict_date"
},
"note": {
"type": "keyword"
},
"treatmentIntakes": {
"type": "object",
"dynamic": true,
"enabled": false
},
"journalCompletion": {
"type": "keyword"
},
"trackers": {
"type": "object",
"dynamic": true,
"properties": {
"symptom": {
"type": "object",
"dynamic": true
}
}
},
"userId": {
"type": "keyword"
}
}
};
await kuzzle.index.create('index');
await kuzzle.collection.create('index', 'collection', mappings);
}
catch (error) {
console.error(error)
}
finally {
kuzzle.disconnect()
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment