-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkibana_vis_post.js
60 lines (50 loc) · 2.33 KB
/
kibana_vis_post.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
const http = require('http');
var fs = require('fs');
// ファイルを読み込む
var data = fs.readFileSync(__dirname + '/racelist.json', 'utf-8');
// JSON形式に変換
var json = JSON.parse(data);
// URL一覧を取得
var race_data = json['url'];
// POST処理
race_data.forEach(function(elem) {
// レースIDを作成
var race_id = elem.replace(/[^0-9]/g,'');
console.log(race_id);
const HOST = "localhost";
const PATH = "/.kibana/visualization/" + race_id;
let postData = {
"title": race_id,
"visState": "{\"title\":\"New Visualization\",\"type\":\"line\",\"params\":{\"addLegend\":true,\"addTimeMarker\":false,\"addTooltip\":true,\"defaultYExtents\":false,\"drawLinesBetweenPoints\":true,\"interpolate\":\"linear\",\"radiusRatio\":9,\"scale\":\"linear\",\"setYExtents\":false,\"shareYAxis\":true,\"showCircles\":true,\"smoothLines\":false,\"times\":[],\"yAxis\":{}},\"aggs\":[{\"id\":\"1\",\"type\":\"min\",\"schema\":\"metric\",\"params\":{\"field\":\"fuku_odds\"}},{\"id\":\"2\",\"type\":\"date_histogram\",\"schema\":\"segment\",\"params\":{\"field\":\"date\",\"interval\":\"auto\",\"customInterval\":\"2h\",\"min_doc_count\":1,\"extended_bounds\":{}}},{\"id\":\"3\",\"type\":\"terms\",\"schema\":\"group\",\"params\":{\"field\":\"umaban\",\"size\":18,\"order\":\"asc\",\"orderBy\":\"_term\"}}],\"listeners\":{}}",
"uiStateJSON": "{}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"*\",\"query\":{\"query_string\":{\"query\":\"" + race_id + "\",\"analyze_wildcard\":true}},\"filter\":[]}"
}
};
let postDataStr = JSON.stringify(postData);
let options = {
host: HOST,
port: 9200,
path: PATH,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': postDataStr.length
}
};
let req = http.request(options, (res) => {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log('BODY: ' + chunk);
});
});
req.on('error', (e) => {
console.log('problem with request: ' + e.message);
});
req.write(postDataStr);
req.end();
});