-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelastic.js
108 lines (98 loc) · 2.22 KB
/
elastic.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
101
102
103
104
105
106
107
108
var request = require('request');
var config = require('config');
var host = config.get('elastic');
var deleteIndex = function () {
request
.del(host + '/events')
.on('response', addIndex);
};
var addIndex = function () {
request
.put(host + '/events')
.on('response', setGeoMapping);
};
var setGeoMapping = function () {
request
.put({
url: host + '/events/event/_mapping',
'content-type': 'application/json',
body: JSON.stringify({
event: {
properties: {
location: {
type: 'geo_point'
}
}
}
})
})
.on('response', addEvents);
};
var addEvents = function () {
request
.post({
url: host + '/events/event',
'content-type': 'application/json',
body: JSON.stringify({
name: 'event 1',
date: new Date(new Date().getTime() + 30 * 60000),
location: {
lat: 54.371675,
lon: 18.616328
}
})
});
request
.post({
url: host + '/events/event',
'content-type': 'application/json',
body: JSON.stringify({
name: 'event 2',
date: new Date(new Date().getTime() + 30 * 60000),
location: {
lat: 54.376675,
lon: 18.621328
}
})
});
request
.post({
url: host + '/events/event',
'content-type': 'application/json',
body: JSON.stringify({
name: 'event 3',
date: new Date(new Date().getTime() + 15 * 60000),
location: {
lat: 54.381675,
lon: 18.626328
}
})
});
request
.post({
url: host + '/events/event',
'content-type': 'application/json',
body: JSON.stringify({
name: 'event 4',
date: new Date(new Date().getTime() + 90 * 60000),
location: {
lat: 54.366675,
lon: 18.621328
}
})
});
request
.post({
url: host + '/events/event',
'content-type': 'application/json',
body: JSON.stringify({
name: 'event 5',
date: new Date(new Date().getTime() + 120 * 60000),
location: {
lat: 54.366675,
lon: 18.611328
}
})
});
};
deleteIndex();