-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
58 lines (48 loc) · 1.19 KB
/
index.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { resolve } from 'path';
export default function (kibana) {
return new kibana.Plugin({
require: ['elasticsearch'],
uiExports: {
fieldFormats: [
'plugins/kibana_codelist_vis/format/index'
]
},
config(Joi) {
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},
init(server, options) {
// Receive information from the backend
server.route({
path: '/api/kibana_codelist_vis/lookup',
method: 'GET',
handler(req, reply) {
// Getting the ES data cluster
var data = server.plugins.elasticsearch.getCluster('data');
// https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html
data.callWithRequest (
req,
'count',
{index:'.x-lff-lookup'}
).then (
response => {
data.callWithRequest(
req,
'search',
{
index: '.x-lff-lookup',
size: response.count
}
).then(function (response) {
reply(response);
}, function (response) {
reply(response);
});
}
).catch (reply ({"hits":{"hits":[]}}))
}
});
}
});
};