opensearch-ts 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +504 -0
- package/README.md +104 -0
- package/dist/aggInput.d.ts +31 -0
- package/dist/aggInput.js +2 -0
- package/dist/aggOutput.d.ts +285 -0
- package/dist/aggOutput.js +2 -0
- package/dist/aggs.d.ts +288 -0
- package/dist/aggs.js +2 -0
- package/dist/attributes.d.ts +25 -0
- package/dist/attributes.js +2 -0
- package/dist/exports.d.ts +8 -0
- package/dist/exports.js +2 -0
- package/dist/fields.d.ts +22 -0
- package/dist/fields.js +2 -0
- package/dist/filters.d.ts +174 -0
- package/dist/filters.js +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +24 -0
- package/dist/logger.d.ts +1 -0
- package/dist/logger.js +7 -0
- package/dist/match.d.ts +27 -0
- package/dist/match.js +2 -0
- package/dist/query.d.ts +6 -0
- package/dist/query.js +37 -0
- package/dist/query.test.d.ts +3 -0
- package/dist/query.test.js +360 -0
- package/dist/search.d.ts +194 -0
- package/dist/search.js +13 -0
- package/dist/testUtil.d.ts +2 -0
- package/dist/testUtil.js +20 -0
- package/dist/tests/Ecommerce.d.ts +60 -0
- package/dist/tests/Ecommerce.js +2 -0
- package/dist/tests/Flight.d.ts +33 -0
- package/dist/tests/Flight.js +2 -0
- package/dist/tests/ServerLog.d.ts +40 -0
- package/dist/tests/ServerLog.js +2 -0
- package/dist/tests/bucket.test.d.ts +1 -0
- package/dist/tests/bucket.test.js +453 -0
- package/dist/tests/ecommercetest.test.d.ts +1 -0
- package/dist/tests/ecommercetest.test.js +83 -0
- package/dist/tests/flights.test.d.ts +1 -0
- package/dist/tests/flights.test.js +48 -0
- package/dist/tests/metric.test.d.ts +1 -0
- package/dist/tests/metric.test.js +258 -0
- package/dist/tests/pipeline.test.d.ts +1 -0
- package/dist/tests/pipeline.test.js +342 -0
- package/dist/typescriptOS.d.ts +38 -0
- package/dist/typescriptOS.js +51 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +7 -0
- package/package.json +46 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const logger = require("../logger");
|
|
4
|
+
const typescriptOS_1 = require("../typescriptOS");
|
|
5
|
+
const testUtil_1 = require("../testUtil");
|
|
6
|
+
var esClient;
|
|
7
|
+
var tsClient;
|
|
8
|
+
jest.setTimeout(20000);
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
esClient = await (0, testUtil_1.makeClientWithEndpoint)();
|
|
11
|
+
tsClient = new typescriptOS_1.TypescriptOSProxyClient(esClient);
|
|
12
|
+
});
|
|
13
|
+
afterAll(async () => {
|
|
14
|
+
await esClient.close();
|
|
15
|
+
});
|
|
16
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/adjacency-matrix/", async () => {
|
|
17
|
+
const search = {
|
|
18
|
+
"size": 0,
|
|
19
|
+
"aggs": {
|
|
20
|
+
"interactions": {
|
|
21
|
+
"adjacency_matrix": {
|
|
22
|
+
"filters": {
|
|
23
|
+
"grpA": {
|
|
24
|
+
"match": {
|
|
25
|
+
"manufacturer.keyword": "Low Tide Media"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"grpB": {
|
|
29
|
+
"match": {
|
|
30
|
+
"manufacturer.keyword": "Elitelligence"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"grpC": {
|
|
34
|
+
"match": {
|
|
35
|
+
"manufacturer.keyword": "Oceanavigations"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
44
|
+
logger.info(result.aggregations.interactions.buckets.map(b => b));
|
|
45
|
+
});
|
|
46
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/date-histogram/", async () => {
|
|
47
|
+
const search = {
|
|
48
|
+
"size": 0,
|
|
49
|
+
"aggs": {
|
|
50
|
+
"logs_per_month": {
|
|
51
|
+
"date_histogram": {
|
|
52
|
+
"field": "@timestamp",
|
|
53
|
+
"interval": "month"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
59
|
+
logger.info(result.aggregations.logs_per_month.buckets.map(b => ({
|
|
60
|
+
key_as_string: b.key_as_string,
|
|
61
|
+
key: b.key,
|
|
62
|
+
doc_count: b.doc_count,
|
|
63
|
+
})));
|
|
64
|
+
});
|
|
65
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/date-range/", async () => {
|
|
66
|
+
const search = {
|
|
67
|
+
"size": 0,
|
|
68
|
+
"aggs": {
|
|
69
|
+
"number_of_bytes": {
|
|
70
|
+
"aggs": {
|
|
71
|
+
"logs": {
|
|
72
|
+
"avg": {
|
|
73
|
+
"field": "memory"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"date_range": {
|
|
78
|
+
"field": "@timestamp",
|
|
79
|
+
"format": "MM-yyyy",
|
|
80
|
+
"ranges": [
|
|
81
|
+
{
|
|
82
|
+
"from": "now-10d/d",
|
|
83
|
+
"to": "now"
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
91
|
+
logger.info(result.aggregations.number_of_bytes.buckets.map(b => ({
|
|
92
|
+
key: b.key,
|
|
93
|
+
from: b.from,
|
|
94
|
+
from_as_string: b.from_as_string,
|
|
95
|
+
to: b.to,
|
|
96
|
+
to_as_string: b.to_as_string,
|
|
97
|
+
doc_count: b.doc_count,
|
|
98
|
+
avgMem: b.logs.value
|
|
99
|
+
})));
|
|
100
|
+
});
|
|
101
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/diversified-sampler/", async () => {
|
|
102
|
+
const search = {
|
|
103
|
+
"size": 0,
|
|
104
|
+
"aggs": {
|
|
105
|
+
"sample": {
|
|
106
|
+
"diversified_sampler": {
|
|
107
|
+
"shard_size": 1000,
|
|
108
|
+
"field": "response.keyword"
|
|
109
|
+
},
|
|
110
|
+
"aggs": {
|
|
111
|
+
"terms": {
|
|
112
|
+
"terms": {
|
|
113
|
+
"field": "agent.keyword"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
121
|
+
logger.info(result.aggregations.sample.doc_count);
|
|
122
|
+
logger.info(result.aggregations.sample.terms);
|
|
123
|
+
});
|
|
124
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/filter/", async () => {
|
|
125
|
+
const search = {
|
|
126
|
+
"size": 0,
|
|
127
|
+
"aggs": {
|
|
128
|
+
"low_value": {
|
|
129
|
+
"filter": {
|
|
130
|
+
"range": {
|
|
131
|
+
"taxful_total_price": {
|
|
132
|
+
"lte": 50
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
"aggs": {
|
|
137
|
+
"avg_amount": {
|
|
138
|
+
"avg": {
|
|
139
|
+
"field": "taxful_total_price"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
147
|
+
logger.info(result.aggregations.low_value.doc_count);
|
|
148
|
+
logger.info(result.aggregations.low_value.avg_amount.value);
|
|
149
|
+
});
|
|
150
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/filters/", async () => {
|
|
151
|
+
const search = {
|
|
152
|
+
"size": 0,
|
|
153
|
+
"aggs": {
|
|
154
|
+
"200_os": {
|
|
155
|
+
"filters": {
|
|
156
|
+
"other_bucket": true,
|
|
157
|
+
"filters": [
|
|
158
|
+
{
|
|
159
|
+
"term": {
|
|
160
|
+
"response.keyword": "200"
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"term": {
|
|
165
|
+
"machine.os.keyword": "osx"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
},
|
|
170
|
+
"aggs": {
|
|
171
|
+
"avg_amount": {
|
|
172
|
+
"avg": {
|
|
173
|
+
"field": "bytes"
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
181
|
+
logger.info(result.aggregations);
|
|
182
|
+
// console.log(result.aggregations["200_os"].avg_amount)
|
|
183
|
+
// console.log(result.aggregations["200_os"].doc_count)
|
|
184
|
+
});
|
|
185
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/multi-terms/", async () => {
|
|
186
|
+
const search = {
|
|
187
|
+
"aggs": {
|
|
188
|
+
"hot": {
|
|
189
|
+
"multi_terms": {
|
|
190
|
+
"terms": [
|
|
191
|
+
{
|
|
192
|
+
"field": "agent.keyword"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"field": "machine.os.keyword"
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
203
|
+
logger.info(result.aggregations);
|
|
204
|
+
});
|
|
205
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/geo-distance/", async () => {
|
|
206
|
+
const search = {
|
|
207
|
+
"size": 0,
|
|
208
|
+
"aggs": {
|
|
209
|
+
"position": {
|
|
210
|
+
"aggs": {
|
|
211
|
+
"max_bytes": {
|
|
212
|
+
"max": {
|
|
213
|
+
"field": "bytes"
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
"geo_distance": {
|
|
218
|
+
"field": "geo.coordinates",
|
|
219
|
+
"origin": {
|
|
220
|
+
"lat": 83.76,
|
|
221
|
+
"lon": -81.2
|
|
222
|
+
},
|
|
223
|
+
"ranges": [
|
|
224
|
+
{
|
|
225
|
+
"to": 10
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
"from": 10,
|
|
229
|
+
"to": 20
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
"from": 20,
|
|
233
|
+
"to": 50
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
"from": 50,
|
|
237
|
+
"to": 100
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
"from": 100
|
|
241
|
+
}
|
|
242
|
+
]
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
248
|
+
logger.info(result.aggregations);
|
|
249
|
+
logger.info(result.aggregations.position.buckets.map(b => b.max_bytes.value));
|
|
250
|
+
});
|
|
251
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/geohash-grid/", async () => {
|
|
252
|
+
const search = {
|
|
253
|
+
"size": 0,
|
|
254
|
+
"aggs": {
|
|
255
|
+
"geo_hash": {
|
|
256
|
+
"geohash_grid": {
|
|
257
|
+
"field": "geo.coordinates",
|
|
258
|
+
"precision": 4
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
264
|
+
logger.info(result.aggregations);
|
|
265
|
+
logger.info(result.aggregations.geo_hash);
|
|
266
|
+
});
|
|
267
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/geohex-grid/", async () => {
|
|
268
|
+
const search = {
|
|
269
|
+
"size": 0,
|
|
270
|
+
"aggs": {
|
|
271
|
+
"grouped": {
|
|
272
|
+
"geohex_grid": {
|
|
273
|
+
"field": "geo.coordinates",
|
|
274
|
+
"precision": 1
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
280
|
+
logger.info(result.aggregations);
|
|
281
|
+
logger.info(result.aggregations.grouped.buckets);
|
|
282
|
+
});
|
|
283
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/geotile-grid/", async () => {
|
|
284
|
+
const search = {
|
|
285
|
+
"size": 0,
|
|
286
|
+
"aggs": {
|
|
287
|
+
"grouped": {
|
|
288
|
+
"geotile_grid": {
|
|
289
|
+
"field": "geo.coordinates",
|
|
290
|
+
"precision": 1
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
296
|
+
logger.info(result.aggregations);
|
|
297
|
+
logger.info(result.aggregations.grouped.buckets);
|
|
298
|
+
});
|
|
299
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/ip-range/", async () => {
|
|
300
|
+
const search = {
|
|
301
|
+
"size": 0,
|
|
302
|
+
"aggs": {
|
|
303
|
+
"access": {
|
|
304
|
+
"ip_range": {
|
|
305
|
+
"field": "ip",
|
|
306
|
+
"ranges": [
|
|
307
|
+
{
|
|
308
|
+
"from": "1.0.0.0",
|
|
309
|
+
"to": "126.158.155.183"
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
"mask": "1.0.0.0/8"
|
|
313
|
+
}
|
|
314
|
+
]
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
320
|
+
logger.info(result.aggregations);
|
|
321
|
+
logger.info(result.aggregations.access);
|
|
322
|
+
});
|
|
323
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/nested/", async () => {
|
|
324
|
+
const search = {
|
|
325
|
+
"query": {
|
|
326
|
+
"match": { "response.keyword": "200" }
|
|
327
|
+
},
|
|
328
|
+
"aggs": {
|
|
329
|
+
"pages": {
|
|
330
|
+
"nested": {
|
|
331
|
+
"path": "pages"
|
|
332
|
+
},
|
|
333
|
+
"aggs": {
|
|
334
|
+
"min_load_time": { "min": { "field": "geo.coordinates.lat" } }
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
340
|
+
logger.info(result.aggregations);
|
|
341
|
+
});
|
|
342
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/reverse-nested/", async () => {
|
|
343
|
+
const search = {
|
|
344
|
+
"query": {
|
|
345
|
+
"match": { "response": "200" }
|
|
346
|
+
},
|
|
347
|
+
"aggs": {
|
|
348
|
+
"pages": {
|
|
349
|
+
"nested": {
|
|
350
|
+
"path": "pages"
|
|
351
|
+
},
|
|
352
|
+
"aggs": {
|
|
353
|
+
"top_pages_per_load_time": {
|
|
354
|
+
"terms": {
|
|
355
|
+
"field": "machine.ram"
|
|
356
|
+
},
|
|
357
|
+
"aggs": {
|
|
358
|
+
"comment_to_logs": {
|
|
359
|
+
"reverse_nested": {},
|
|
360
|
+
"aggs": {
|
|
361
|
+
"min_load_time": {
|
|
362
|
+
"min": {
|
|
363
|
+
"field": "machine.ram"
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
375
|
+
logger.info(result.aggregations);
|
|
376
|
+
});
|
|
377
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/sampler/", async () => {
|
|
378
|
+
const search = {
|
|
379
|
+
"size": 0,
|
|
380
|
+
"aggs": {
|
|
381
|
+
"sample": {
|
|
382
|
+
"sampler": {
|
|
383
|
+
"shard_size": 1000
|
|
384
|
+
},
|
|
385
|
+
"aggs": {
|
|
386
|
+
"terms": {
|
|
387
|
+
"terms": {
|
|
388
|
+
"field": "agent.keyword"
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
396
|
+
logger.info(result.aggregations.sample.terms.buckets);
|
|
397
|
+
});
|
|
398
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/significant-terms/", async () => {
|
|
399
|
+
const search = {
|
|
400
|
+
"size": 0,
|
|
401
|
+
"query": {
|
|
402
|
+
"terms": {
|
|
403
|
+
"machine.os.keyword": [
|
|
404
|
+
"ios"
|
|
405
|
+
]
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
"aggs": {
|
|
409
|
+
"significant_response_codes": {
|
|
410
|
+
"significant_terms": {
|
|
411
|
+
"field": "agent.keyword"
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
417
|
+
logger.info(result.aggregations.significant_response_codes.bg_count);
|
|
418
|
+
logger.info(result.aggregations.significant_response_codes.doc_count);
|
|
419
|
+
logger.info(result.aggregations.significant_response_codes.buckets);
|
|
420
|
+
});
|
|
421
|
+
test("https://opensearch.org/docs/latest/aggregations/bucket/significant-text/", async () => {
|
|
422
|
+
const search = {
|
|
423
|
+
"query": {
|
|
424
|
+
"match": {
|
|
425
|
+
"agent": "Firefox",
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
"aggs": {
|
|
429
|
+
"my_sample": {
|
|
430
|
+
"sampler": {
|
|
431
|
+
"shard_size": 100
|
|
432
|
+
},
|
|
433
|
+
"aggs": {
|
|
434
|
+
"keywords": {
|
|
435
|
+
"significant_text": {
|
|
436
|
+
"field": "agent",
|
|
437
|
+
"min_doc_count": 4
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
445
|
+
logger.info(result.aggregations.my_sample.keywords.bg_count);
|
|
446
|
+
logger.info(result.aggregations.my_sample.keywords.doc_count);
|
|
447
|
+
logger.info(result.aggregations.my_sample.keywords.buckets.map(b => ({
|
|
448
|
+
bg_count: b.bg_count,
|
|
449
|
+
doc_count: b.doc_count,
|
|
450
|
+
key: b.key,
|
|
451
|
+
score: b.score,
|
|
452
|
+
})));
|
|
453
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const logger = require("../logger");
|
|
4
|
+
const typescriptOS_1 = require("../typescriptOS");
|
|
5
|
+
const testUtil_1 = require("../testUtil");
|
|
6
|
+
var esClient;
|
|
7
|
+
var tsClient;
|
|
8
|
+
jest.setTimeout(20000);
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
esClient = await (0, testUtil_1.makeClientWithEndpoint)();
|
|
11
|
+
tsClient = new typescriptOS_1.TypescriptOSProxyClient(esClient);
|
|
12
|
+
});
|
|
13
|
+
afterAll(async () => {
|
|
14
|
+
await esClient.close();
|
|
15
|
+
});
|
|
16
|
+
test("ecommerce", async () => {
|
|
17
|
+
const search = {
|
|
18
|
+
"aggs": {
|
|
19
|
+
"order_trend": {
|
|
20
|
+
"date_histogram": {
|
|
21
|
+
"interval": "month",
|
|
22
|
+
"field": "order_date"
|
|
23
|
+
},
|
|
24
|
+
"aggs": {
|
|
25
|
+
"region": {
|
|
26
|
+
"terms": {
|
|
27
|
+
"field": "geoip.region_name"
|
|
28
|
+
},
|
|
29
|
+
"aggs": {
|
|
30
|
+
"sum_region": {
|
|
31
|
+
"sum": {
|
|
32
|
+
"field": "taxful_total_price"
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
"terms_gender": {
|
|
36
|
+
"terms": {
|
|
37
|
+
"field": "customer_gender"
|
|
38
|
+
},
|
|
39
|
+
"aggs": {
|
|
40
|
+
"sum_region_gender": {
|
|
41
|
+
"sum": {
|
|
42
|
+
"field": "taxful_total_price"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
54
|
+
logger.info(result.aggregations);
|
|
55
|
+
});
|
|
56
|
+
test("ranges", async () => {
|
|
57
|
+
const search = {
|
|
58
|
+
"aggs": {
|
|
59
|
+
"rangetest": {
|
|
60
|
+
"range": {
|
|
61
|
+
"keyed": false,
|
|
62
|
+
"field": "products.price",
|
|
63
|
+
"ranges": [
|
|
64
|
+
{
|
|
65
|
+
"from": 0,
|
|
66
|
+
"to": 1
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"from": 1,
|
|
70
|
+
"to": 100
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"from": 100,
|
|
74
|
+
"to": 200
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
82
|
+
console.log(result.aggregations.rangetest.buckets.map(b => b));
|
|
83
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const typescriptOS_1 = require("../typescriptOS");
|
|
4
|
+
const testUtil_1 = require("../testUtil");
|
|
5
|
+
var esClient;
|
|
6
|
+
var tsClient;
|
|
7
|
+
jest.setTimeout(20000);
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
esClient = await (0, testUtil_1.makeClientWithEndpoint)();
|
|
10
|
+
tsClient = new typescriptOS_1.TypescriptOSProxyClient(esClient);
|
|
11
|
+
});
|
|
12
|
+
afterAll(async () => {
|
|
13
|
+
await esClient.close();
|
|
14
|
+
});
|
|
15
|
+
test("flights", async () => {
|
|
16
|
+
const search = {
|
|
17
|
+
"size": 0,
|
|
18
|
+
"aggs": {
|
|
19
|
+
"country": {
|
|
20
|
+
"terms": {
|
|
21
|
+
"field": "DestCountry",
|
|
22
|
+
"size": 10
|
|
23
|
+
},
|
|
24
|
+
"aggs": {
|
|
25
|
+
"histogram": {
|
|
26
|
+
"date_histogram": {
|
|
27
|
+
"field": "timestamp",
|
|
28
|
+
"interval": "week"
|
|
29
|
+
},
|
|
30
|
+
"aggs": {
|
|
31
|
+
"avg_price": {
|
|
32
|
+
"avg": {
|
|
33
|
+
"field": "AvgTicketPrice"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_flights" });
|
|
43
|
+
console.log(result.aggregations.country.buckets.flatMap(c => c.histogram.buckets.flatMap(h => ({
|
|
44
|
+
country: c.key,
|
|
45
|
+
avg_price: h.avg_price.value,
|
|
46
|
+
date: new Date(h.key_as_string)
|
|
47
|
+
}))));
|
|
48
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|