-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_migrate.js
217 lines (206 loc) · 5.37 KB
/
data_migrate.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
var elasticsearch = require('elasticsearch');
var request = require('request');
var data = {};
request('http://mock-api.smartermeasure.com/v4/results', function (err, response, body) {
if (err) {
console.log(err);
} else {
data = JSON.parse(body);
//indexData(data);
basicSearch('first location');
suggestSearch('Anthiny');
//tokenizer types = standard, edgeNGram, keyword, letter, lowercase, nGram, whitespace, pattern, uax_url_email, path_hierarchy, classic
searchAnalize('This is a new blahh', 'nGram');
count('technical_knowledge');
narrowSearch('Anthony');
rangeSearch(987071190, 987071190);
statFacet();
agg();
Bucketagg();
addLocation();
geo();
}
});
var client = new elasticsearch.Client({
host: 'https://VOCFRfp406LdFsRmlkhEwGI2zV57kHEi:@jordantest.east-us.azr.facetflow.io',
apiVersion: '1.0'
});
function addLocation() {
client.index({
index: 'newlocations',
type: 'object',
body: {
name: "blhhhrrr",
location: { lat : 52.3760, lon : 4.894 }
}
}, function (error, response) {
console.log(response);
});
}
/*
function indexData(data) {
for (var i = 0; i < data.results.length; i++) {
client.index({
index: 'myindex',
type: 'object',
tokenizer: 'whitespace',
id: "1",
body: {
this1: {
blahh: "blahh",
nested: {
thats: "one",
supernested: {
value: "this"
}
}
}
}
}, function (error, response) {
});
}
}
*/
//basic search
function basicSearch(searchTerm) {
client.search({
index: 'locations',
q: searchTerm
}, function (error, response) {
//console.log(response.hits.hits);
});
}
//used for autocorrect mis type.
function suggestSearch(searchTerm) {
client.suggest({
index: 'myindex',
body: {
mysuggester: {
text: searchTerm,
term: {
field: 'first_name'
}
}
}
}, function (error, response) {
//console.log(response.mysuggester[0]);
});
}
//Shows the results of different tokenizers on index of text.
function searchAnalize(searchTerm, token) {
client.indices.analyze({
index: 'myindex',
text: searchTerm,
tokenizer: token
}, function (error, response) {
//console.log(response);
});
}
//used to get amount of documents containing, Good because its quick compared to a full query
function count(searchTerm) {
client.count({
index: 'myindex',
q: searchTerm
}, function (err, response) {
//console.log(response);
});
}
function narrowSearch(searchTerm) {
client.search({
index: 'myindex',
q: searchTerm,
fields: ['first_name', 'last_name', 'email_address']
}, function (error, response) {
//console.log(response.hits.hits[0]);
});
}
//returns values between specified dates
function rangeSearch(dateOne, dateTwo) {
client.search({
index: 'myindex',
body: {
"query" : {
"match_all" : {}
},
filter : {
range : {
date_started : {
gte: dateOne,
lte: dateTwo
}
}
}
}
}, function (error, response) {
//console.log(response.hits.hits);
});
}
//returns stats on the date_started like average date started
function statFacet() {
client.search({
index: 'myindex',
body: {
"query" : {
"match_all" : {}
},
facets : {
stat1 : {
statistical : {
field : "date_started"
}
}
}
}
}, function (error, response) {
//console.log(response.facets);
});
}
function agg() {
client.search({
index: 'myindex',
body: {
aggs : {
first_date : { min : { field : "date_started" } }
}
}
}, function (error, response) {
//console.log(response.aggregations);
});
}
function Bucketagg() {
client.search({
index: 'myindex',
body: {
aggs : {
date_buckets : {
percentiles : {
field : "date_started"
}
}
}
}
}, function (error, response) {
//console.log(response.aggregations);
});
}
function geo() {
client.search({
index: 'newlocations',
body: {
aggs : {
rings : {
geo_distance : {
field : "location",
origin : { "lat" : 60, "lon" : 20 },
unit : "mi",
ranges : [
{ to : 1 }
]
}
}
}
}
}, function (error, response) {
console.log(response.aggregations.rings);
});
}