Created
November 28, 2019 03:50
-
-
Save Aschen/e4467cd2e0d40d3d15e1a74d770079b4 to your computer and use it in GitHub Desktop.
Create Kuzzle collection with mappings
This file contains hidden or 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 { | |
| 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