-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
100 lines (89 loc) · 3.18 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
module.exports = function(kibana) {
return new kibana.Plugin({
// Export the front-end visualization definition.
uiExports: {
visTypes: [
"plugins/kibana-chord/chord"
]
},
// Define our custom server-side middleware for
// custom ElasticSearch queries.
init: function (server, options) {
// This route is for the initial search query.
server.route({
path: "/api/kibana-chord",
method: "POST",
handler: function(req, reply) {
// The payload can be expected to have the following properties:
//
// * d.index - Name of the ES index to query.
// * d.time - Parameters from the global Kibana time selector.
// * d.source - Value for the source of the clicked ribbon.
// * d.destination - Value for the destination of the clicked ribbon.
var d = req.payload;
// Unpack the query parameters from the client.
var index = req.payload.index;
var time = req.payload.time;
// TODO include sourceField, destField from client Schema config
var options = {
index: index,
scroll: "30s",
body: {
sort: [
{ "timestamp": { "order": "desc" } }
],
query: {
bool: {
should: [
{
"bool": {
"must": [
{"term": {"nuage_metadata.sourcepolicygroups": d.source} },
{ "term": {"nuage_metadata.destinationpolicygroups": d.destination} },
{"range": { "timestamp": time }}
]
}
},
{
"bool": {
"must": [
{ "term": {"nuage_metadata.sourcepolicygroups": d.destination} },
{ "term": {"nuage_metadata.destinationpolicygroups": d.source} },
{"range": { "timestamp": time }}
]
}
}
]
}
}
}
};
// Execute the query and pass it to the client as JSON.
server.plugins.elasticsearch
.callWithRequest(req, "search", options)
.then(function (response) {
reply(JSON.stringify(response, null, 2));
});
}
});
// This route is for scrolling through results.
server.route({
path: "/api/kibana-chord-scroll",
method: "POST",
handler: function(req, reply) {
console.log("Inside Scroll Handler");
// The payload will have
// * scrollId - The scroll key/cursor for fetching more data.
// * scroll - The scroll consistency time.
var options = req.payload;
// Execute the query and pass it to the client as JSON.
server.plugins.elasticsearch
.callWithRequest(req, "scroll", options)
.then(function (response) {
reply(JSON.stringify(response, null, 2));
});
}
});
}
});
};