-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathseed.js
40 lines (32 loc) · 1.22 KB
/
seed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const PreferenceIndexDefinition = require('./src/schemas/preference.esindex.json')
const SlotIndexDefinition = require('./src/schemas/slot.esindex.json')
const Axios = require('axios')
const { ES_DOMAIN_ENDPOINT, PREFERENCES_INDEX, SLOTS_INDEX } = process.env
const es = async () => {
try {
await Axios.put(`https://${ES_DOMAIN_ENDPOINT}/${PREFERENCES_INDEX}`, PreferenceIndexDefinition)
} catch (prefPutErr) {
await Axios.put(`https://${ES_DOMAIN_ENDPOINT}/${PREFERENCES_INDEX}/_mapping`, PreferenceIndexDefinition.mappings)
}
try {
await Axios.put(`https://${ES_DOMAIN_ENDPOINT}/${SLOTS_INDEX}`, SlotIndexDefinition)
} catch (slotPutErr) {
await Axios.put(`https://${ES_DOMAIN_ENDPOINT}/${SLOTS_INDEX}/_mappings`, SlotIndexDefinition.mappings)
}
return 'ok'
}
const pingEs = async () => {
const response = (await Axios.get(`https://${ES_DOMAIN_ENDPOINT}/_search`, { params: { size: '1000' } })).data
console.log('%j', response)
return JSON.stringify(response, null, 2)
}
const execute = async ({ url, arg, method }) => {
const response = (await Axios[method](url, arg)).data
console.log('%j', response)
return JSON.stringify(response, null, 2)
}
module.exports = {
es,
pingEs,
execute
}