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,258 @@
|
|
|
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/metric/average/", async () => {
|
|
17
|
+
const search = {
|
|
18
|
+
"size": 0,
|
|
19
|
+
"aggs": {
|
|
20
|
+
"avg_taxful_total_price": {
|
|
21
|
+
"avg": {
|
|
22
|
+
"field": "taxful_total_price"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
28
|
+
logger.info(result.aggregations.avg_taxful_total_price.value);
|
|
29
|
+
});
|
|
30
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/cardinality/", async () => {
|
|
31
|
+
const search = {
|
|
32
|
+
"size": 0,
|
|
33
|
+
"aggs": {
|
|
34
|
+
"unique_products": {
|
|
35
|
+
"cardinality": {
|
|
36
|
+
"field": "products.product_id"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
42
|
+
logger.info(result.aggregations.unique_products.value);
|
|
43
|
+
});
|
|
44
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/extended-stats/", async () => {
|
|
45
|
+
const search = {
|
|
46
|
+
"size": 0,
|
|
47
|
+
"aggs": {
|
|
48
|
+
"extended_stats_taxful_total_price": {
|
|
49
|
+
"extended_stats": {
|
|
50
|
+
"field": "taxful_total_price"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
56
|
+
logger.info(result.aggregations.extended_stats_taxful_total_price);
|
|
57
|
+
});
|
|
58
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/extended-stats/ sigma", async () => {
|
|
59
|
+
const search = {
|
|
60
|
+
"size": 0,
|
|
61
|
+
"aggs": {
|
|
62
|
+
"extended_stats_taxful_total_price": {
|
|
63
|
+
"extended_stats": {
|
|
64
|
+
"field": "taxful_total_price",
|
|
65
|
+
"sigma": 3
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
71
|
+
logger.info(result.aggregations.extended_stats_taxful_total_price);
|
|
72
|
+
});
|
|
73
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/geobounds/", async () => {
|
|
74
|
+
const search = {
|
|
75
|
+
"size": 0,
|
|
76
|
+
"aggs": {
|
|
77
|
+
"geo": {
|
|
78
|
+
"geo_bounds": {
|
|
79
|
+
"field": "geoip.location"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
85
|
+
logger.info(result.aggregations.geo.bounds);
|
|
86
|
+
});
|
|
87
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/matrix-stats/", async () => {
|
|
88
|
+
const search = {
|
|
89
|
+
"size": 0,
|
|
90
|
+
"aggs": {
|
|
91
|
+
"matrix_stats_taxful_total_price": {
|
|
92
|
+
"matrix_stats": {
|
|
93
|
+
"fields": ["taxful_total_price", "products.base_price"]
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
99
|
+
logger.info(result.aggregations.matrix_stats_taxful_total_price.fields);
|
|
100
|
+
});
|
|
101
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/maximum/", async () => {
|
|
102
|
+
const search = {
|
|
103
|
+
"size": 0,
|
|
104
|
+
"aggs": {
|
|
105
|
+
"max_taxful_total_price": {
|
|
106
|
+
"max": {
|
|
107
|
+
"field": "taxful_total_price"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
113
|
+
logger.info(result.aggregations.max_taxful_total_price.value);
|
|
114
|
+
});
|
|
115
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/minimum/", async () => {
|
|
116
|
+
const search = {
|
|
117
|
+
"size": 0,
|
|
118
|
+
"aggs": {
|
|
119
|
+
"min_taxful_total_price": {
|
|
120
|
+
"min": {
|
|
121
|
+
"field": "taxful_total_price"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
127
|
+
logger.info(result.aggregations.min_taxful_total_price.value);
|
|
128
|
+
});
|
|
129
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/percentile-ranks/", async () => {
|
|
130
|
+
const search = {
|
|
131
|
+
"size": 0,
|
|
132
|
+
"aggs": {
|
|
133
|
+
"percentile_rank_taxful_total_price": {
|
|
134
|
+
"percentile_ranks": {
|
|
135
|
+
"field": "taxful_total_price",
|
|
136
|
+
"values": [
|
|
137
|
+
10,
|
|
138
|
+
15
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
145
|
+
logger.info(result.aggregations.percentile_rank_taxful_total_price.values);
|
|
146
|
+
});
|
|
147
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/percentile/", async () => {
|
|
148
|
+
const search = {
|
|
149
|
+
"size": 0,
|
|
150
|
+
"aggs": {
|
|
151
|
+
"percentile_taxful_total_price": {
|
|
152
|
+
"percentiles": {
|
|
153
|
+
"field": "taxful_total_price",
|
|
154
|
+
"percents": [
|
|
155
|
+
50
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
162
|
+
logger.info(result.aggregations.percentile_taxful_total_price.values);
|
|
163
|
+
});
|
|
164
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/scripted-metric/", async () => {
|
|
165
|
+
const search = {
|
|
166
|
+
"size": 0,
|
|
167
|
+
"aggs": {
|
|
168
|
+
"responses.counts": {
|
|
169
|
+
"scripted_metric": {
|
|
170
|
+
"init_script": "state.responses = ['error':0L,'success':0L,'other':0L]",
|
|
171
|
+
"map_script": `
|
|
172
|
+
def code = doc['response.keyword'].value;
|
|
173
|
+
if (code.startsWith('5') || code.startsWith('4')) {
|
|
174
|
+
state.responses.error += 1 ;
|
|
175
|
+
} else if(code.startsWith('2')) {
|
|
176
|
+
state.responses.success += 1;
|
|
177
|
+
} else {
|
|
178
|
+
state.responses.other += 1;
|
|
179
|
+
}
|
|
180
|
+
`,
|
|
181
|
+
"combine_script": "state.responses",
|
|
182
|
+
"reduce_script": `
|
|
183
|
+
def counts = ['error': 0L, 'success': 0L, 'other': 0L];
|
|
184
|
+
for (responses in states) {
|
|
185
|
+
counts.error += responses['error'];
|
|
186
|
+
counts.success += responses['success'];
|
|
187
|
+
counts.other += responses['other'];
|
|
188
|
+
}
|
|
189
|
+
return counts;
|
|
190
|
+
`
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
196
|
+
logger.info(result.aggregations["responses.counts"].value.error);
|
|
197
|
+
logger.info(result.aggregations["responses.counts"].value.other);
|
|
198
|
+
logger.info(result.aggregations["responses.counts"].value.success);
|
|
199
|
+
});
|
|
200
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/stats/", async () => {
|
|
201
|
+
const search = {
|
|
202
|
+
"size": 0,
|
|
203
|
+
"aggs": {
|
|
204
|
+
"stats_taxful_total_price": {
|
|
205
|
+
"stats": {
|
|
206
|
+
"field": "taxful_total_price"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
212
|
+
logger.info(result.aggregations.stats_taxful_total_price);
|
|
213
|
+
});
|
|
214
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/sum/", async () => {
|
|
215
|
+
const search = {
|
|
216
|
+
"size": 0,
|
|
217
|
+
"aggs": {
|
|
218
|
+
"sum_taxful_total_price": {
|
|
219
|
+
"sum": {
|
|
220
|
+
"field": "taxful_total_price"
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
226
|
+
logger.info(result.aggregations.sum_taxful_total_price.value);
|
|
227
|
+
});
|
|
228
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/top-hits/", async () => {
|
|
229
|
+
const search = {
|
|
230
|
+
"size": 0,
|
|
231
|
+
"aggs": {
|
|
232
|
+
"top_hits_products": {
|
|
233
|
+
"top_hits": {
|
|
234
|
+
"size": 5
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
240
|
+
logger.info(result.aggregations.top_hits_products.hits.hits);
|
|
241
|
+
logger.info(result.aggregations.top_hits_products.hits.total.value);
|
|
242
|
+
logger.info(result.aggregations.top_hits_products.hits.total.relation);
|
|
243
|
+
logger.info(result.aggregations.top_hits_products.hits.max_score);
|
|
244
|
+
});
|
|
245
|
+
test("https://opensearch.org/docs/latest/aggregations/metric/top-hits/", async () => {
|
|
246
|
+
const search = {
|
|
247
|
+
"size": 0,
|
|
248
|
+
"aggs": {
|
|
249
|
+
"number_of_values": {
|
|
250
|
+
"value_count": {
|
|
251
|
+
"field": "taxful_total_price"
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_ecommerce" });
|
|
257
|
+
logger.info(result.aggregations.number_of_values.value);
|
|
258
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,342 @@
|
|
|
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/pipeline-agg/#quick-example", async () => {
|
|
17
|
+
const search = {
|
|
18
|
+
"size": 0,
|
|
19
|
+
"aggs": {
|
|
20
|
+
"number_of_bytes": {
|
|
21
|
+
"histogram": {
|
|
22
|
+
"field": "bytes",
|
|
23
|
+
"interval": 10000
|
|
24
|
+
},
|
|
25
|
+
"aggs": {
|
|
26
|
+
"sum_total_memory": {
|
|
27
|
+
"sum": {
|
|
28
|
+
"field": "phpmemory"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"sum_copies": {
|
|
34
|
+
"sum_bucket": {
|
|
35
|
+
"buckets_path": "number_of_bytes>sum_total_memory"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
41
|
+
logger.info(result.aggregations.number_of_bytes);
|
|
42
|
+
logger.info(result.aggregations.sum_copies);
|
|
43
|
+
});
|
|
44
|
+
test("https://opensearch.org/docs/latest/aggregations/pipeline-agg/#avg_bucket-sum_bucket-min_bucket-max_bucket", async () => {
|
|
45
|
+
const search = {
|
|
46
|
+
"size": 0,
|
|
47
|
+
"aggs": {
|
|
48
|
+
"visits_per_month": {
|
|
49
|
+
"date_histogram": {
|
|
50
|
+
"field": "@timestamp",
|
|
51
|
+
"interval": "month"
|
|
52
|
+
},
|
|
53
|
+
"aggs": {
|
|
54
|
+
"sum_of_bytes": {
|
|
55
|
+
"sum": {
|
|
56
|
+
"field": "bytes"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"avg_monthly_bytes": {
|
|
62
|
+
"avg_bucket": {
|
|
63
|
+
"buckets_path": "visits_per_month>sum_of_bytes"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
69
|
+
logger.info(result.aggregations.avg_monthly_bytes);
|
|
70
|
+
logger.info(result.aggregations.visits_per_month);
|
|
71
|
+
});
|
|
72
|
+
test("https://opensearch.org/docs/latest/aggregations/pipeline-agg/#stats_bucket-extended_stats_bucket", async () => {
|
|
73
|
+
const search = {
|
|
74
|
+
"size": 0,
|
|
75
|
+
"aggs": {
|
|
76
|
+
"visits_per_month": {
|
|
77
|
+
"date_histogram": {
|
|
78
|
+
"field": "@timestamp",
|
|
79
|
+
"interval": "month"
|
|
80
|
+
},
|
|
81
|
+
"aggs": {
|
|
82
|
+
"sum_of_bytes": {
|
|
83
|
+
"sum": {
|
|
84
|
+
"field": "bytes"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"stats_monthly_bytes": {
|
|
90
|
+
"stats_bucket": {
|
|
91
|
+
"buckets_path": "visits_per_month>sum_of_bytes"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
97
|
+
logger.info(result.aggregations.stats_monthly_bytes);
|
|
98
|
+
logger.info(result.aggregations.visits_per_month);
|
|
99
|
+
});
|
|
100
|
+
// bucket_script, bucket_selector
|
|
101
|
+
test("https://opensearch.org/docs/latest/aggregations/pipeline-agg/#bucket_script-bucket_selector", async () => {
|
|
102
|
+
const search = {
|
|
103
|
+
"size": 0,
|
|
104
|
+
"aggs": {
|
|
105
|
+
"sales_per_month": {
|
|
106
|
+
"histogram": {
|
|
107
|
+
"field": "bytes",
|
|
108
|
+
"interval": "10000"
|
|
109
|
+
},
|
|
110
|
+
"aggs": {
|
|
111
|
+
"total_ram": {
|
|
112
|
+
"sum": {
|
|
113
|
+
"field": "machine.ram"
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
"ext-type": {
|
|
117
|
+
"filter": {
|
|
118
|
+
"term": {
|
|
119
|
+
"extension.keyword": "zip"
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"aggs": {
|
|
123
|
+
"total_ram": {
|
|
124
|
+
"sum": {
|
|
125
|
+
"field": "machine.ram"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
"ram-percentage": {
|
|
131
|
+
"bucket_script": {
|
|
132
|
+
"buckets_path": {
|
|
133
|
+
"machineRam": "ext-type>total_ram",
|
|
134
|
+
"totalRam": "total_ram"
|
|
135
|
+
},
|
|
136
|
+
"script": "params.machineRam / params.totalRam"
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
144
|
+
logger.info(result.aggregations.sales_per_month.buckets);
|
|
145
|
+
});
|
|
146
|
+
/**
|
|
147
|
+
test("params.totalBytes > 20000 bucket_selector", async () => {
|
|
148
|
+
|
|
149
|
+
type QuickExample = Search<ServerLog,
|
|
150
|
+
{
|
|
151
|
+
bytes_per_month : {
|
|
152
|
+
agg : "date_histogram",
|
|
153
|
+
aggs : {
|
|
154
|
+
"total_bytes" : {
|
|
155
|
+
agg : "sum"
|
|
156
|
+
},
|
|
157
|
+
"bytes_bucket_filter" : {
|
|
158
|
+
agg : "bucket_selector"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}>
|
|
163
|
+
|
|
164
|
+
const search : QuickExample =
|
|
165
|
+
{
|
|
166
|
+
"size": 0,
|
|
167
|
+
"aggs": {
|
|
168
|
+
"bytes_per_month": {
|
|
169
|
+
"date_histogram": {
|
|
170
|
+
"field": "@timestamp",
|
|
171
|
+
"calendar_interval": "month"
|
|
172
|
+
},
|
|
173
|
+
"aggs": {
|
|
174
|
+
"total_bytes": {
|
|
175
|
+
"sum": {
|
|
176
|
+
"field": "bytes"
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
"bytes_bucket_filter": {
|
|
180
|
+
"bucket_selector": {
|
|
181
|
+
"buckets_path": {
|
|
182
|
+
"totalBytes": "total_bytes"
|
|
183
|
+
},
|
|
184
|
+
"script": "params.totalBytes > 20000"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const result = await tsClient.searchTS({body : search, index : "opensearch_dashboards_sample_data_logs"})
|
|
193
|
+
|
|
194
|
+
logger.info(result.aggregations.bytes_per_month.buckets.map(b => b.bytes_bucket_filter))
|
|
195
|
+
logger.info(result.aggregations.bytes_per_month.buckets.map(b => b))
|
|
196
|
+
|
|
197
|
+
})
|
|
198
|
+
*/
|
|
199
|
+
test("https://opensearch.org/docs/latest/aggregations/pipeline-agg/#bucket_sort", async () => {
|
|
200
|
+
const search = {
|
|
201
|
+
"size": 0,
|
|
202
|
+
"aggs": {
|
|
203
|
+
"sales_per_month": {
|
|
204
|
+
"date_histogram": {
|
|
205
|
+
"field": "@timestamp",
|
|
206
|
+
"calendar_interval": "month"
|
|
207
|
+
},
|
|
208
|
+
"aggs": {
|
|
209
|
+
"total_bytes": {
|
|
210
|
+
"sum": {
|
|
211
|
+
"field": "bytes"
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
"bytes_bucket_sort": {
|
|
215
|
+
"bucket_sort": {
|
|
216
|
+
"sort": [
|
|
217
|
+
{ "total_bytes": { "order": "desc" } }
|
|
218
|
+
],
|
|
219
|
+
"size": 3
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
227
|
+
logger.info(result.aggregations.sales_per_month.buckets.map(b => ({
|
|
228
|
+
"key_as_string": b.key_as_string,
|
|
229
|
+
"key": b.key,
|
|
230
|
+
"doc_count": b.doc_count,
|
|
231
|
+
"total_bytes": {
|
|
232
|
+
"value": b.total_bytes.value
|
|
233
|
+
}
|
|
234
|
+
})));
|
|
235
|
+
});
|
|
236
|
+
test("https://opensearch.org/docs/latest/aggregations/pipeline-agg/#cumulative_sum", async () => {
|
|
237
|
+
const search = {
|
|
238
|
+
"size": 0,
|
|
239
|
+
"aggs": {
|
|
240
|
+
"sales_per_month": {
|
|
241
|
+
"date_histogram": {
|
|
242
|
+
"field": "@timestamp",
|
|
243
|
+
"calendar_interval": "month"
|
|
244
|
+
},
|
|
245
|
+
"aggs": {
|
|
246
|
+
"number_of_bytes": {
|
|
247
|
+
"sum": {
|
|
248
|
+
"field": "bytes"
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
"cumulative_bytes": {
|
|
252
|
+
"cumulative_sum": {
|
|
253
|
+
"buckets_path": "number_of_bytes"
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
261
|
+
logger.info(result.aggregations.sales_per_month.buckets.map(b => b.cumulative_bytes.value));
|
|
262
|
+
});
|
|
263
|
+
test("https://opensearch.org/docs/latest/aggregations/pipeline-agg/#cumulative_sum", async () => {
|
|
264
|
+
const search = {
|
|
265
|
+
"size": 0,
|
|
266
|
+
"aggs": {
|
|
267
|
+
"sales_per_month": {
|
|
268
|
+
"date_histogram": {
|
|
269
|
+
"field": "@timestamp",
|
|
270
|
+
"calendar_interval": "month"
|
|
271
|
+
},
|
|
272
|
+
"aggs": {
|
|
273
|
+
"number_of_bytes": {
|
|
274
|
+
"sum": {
|
|
275
|
+
"field": "bytes"
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
"bytes_deriv": {
|
|
279
|
+
"derivative": {
|
|
280
|
+
"buckets_path": "number_of_bytes"
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
288
|
+
logger.info(result.aggregations.sales_per_month.buckets.map(b => b.bytes_deriv));
|
|
289
|
+
});
|
|
290
|
+
test("https://opensearch.org/docs/latest/aggregations/pipeline-agg/#moving_avg", async () => {
|
|
291
|
+
const search = {
|
|
292
|
+
"size": 0,
|
|
293
|
+
"aggs": {
|
|
294
|
+
"my_date_histogram": {
|
|
295
|
+
"date_histogram": {
|
|
296
|
+
"field": "@timestamp",
|
|
297
|
+
"calendar_interval": "month"
|
|
298
|
+
},
|
|
299
|
+
"aggs": {
|
|
300
|
+
"sum_of_bytes": {
|
|
301
|
+
"sum": { "field": "bytes" }
|
|
302
|
+
},
|
|
303
|
+
"moving_avg_of_sum_of_bytes": {
|
|
304
|
+
"moving_avg": {
|
|
305
|
+
"buckets_path": "sum_of_bytes"
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
313
|
+
logger.info(result.aggregations.my_date_histogram.buckets.map(b => { var _a; return (_a = b === null || b === void 0 ? void 0 : b.moving_avg_of_sum_of_bytes) === null || _a === void 0 ? void 0 : _a.value; }));
|
|
314
|
+
});
|
|
315
|
+
test("https://opensearch.org/docs/latest/aggregations/pipeline-agg/#serial_diff", async () => {
|
|
316
|
+
const search = {
|
|
317
|
+
"size": 0,
|
|
318
|
+
"aggs": {
|
|
319
|
+
"my_date_histogram": {
|
|
320
|
+
"date_histogram": {
|
|
321
|
+
"field": "@timestamp",
|
|
322
|
+
"calendar_interval": "day"
|
|
323
|
+
},
|
|
324
|
+
"aggs": {
|
|
325
|
+
"the_sum": {
|
|
326
|
+
"sum": {
|
|
327
|
+
"field": "bytes"
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
"thirtieth_difference": {
|
|
331
|
+
"serial_diff": {
|
|
332
|
+
"buckets_path": "the_sum",
|
|
333
|
+
"lag": 7
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
const result = await tsClient.searchTS({ body: search, index: "opensearch_dashboards_sample_data_logs" });
|
|
341
|
+
logger.info(result.aggregations.my_date_histogram.buckets);
|
|
342
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as os from "@opensearch-project/opensearch";
|
|
2
|
+
import { TransportRequestOptions } from "@opensearch-project/opensearch/lib/Transport";
|
|
3
|
+
import * as q from "./search";
|
|
4
|
+
import { AggsQuery } from "./aggInput";
|
|
5
|
+
export declare const IGNORE_ATTS: string[];
|
|
6
|
+
export type DictResponse<T, MSEARCH extends {
|
|
7
|
+
[a: string]: q.Search<T, AggsQuery>;
|
|
8
|
+
}> = {
|
|
9
|
+
[K in keyof MSEARCH]: q.SearchResponse<T, AggsQuery>;
|
|
10
|
+
};
|
|
11
|
+
export type MSearch<T> = {
|
|
12
|
+
[key: string]: q.Search<T, AggsQuery>;
|
|
13
|
+
};
|
|
14
|
+
export type CountResponse = {
|
|
15
|
+
"count": number;
|
|
16
|
+
"_shards": {
|
|
17
|
+
"total": number;
|
|
18
|
+
"successful": number;
|
|
19
|
+
"skipped": number;
|
|
20
|
+
"failed": number;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export declare class TypescriptOSProxyClient {
|
|
24
|
+
esClient: os.Client;
|
|
25
|
+
constructor(esClient: os.Client);
|
|
26
|
+
countTs<T, A extends AggsQuery>(search: {
|
|
27
|
+
body: q.Search<T, A>;
|
|
28
|
+
index?: string;
|
|
29
|
+
}, options?: TransportRequestOptions): Promise<CountResponse>;
|
|
30
|
+
searchTS<T, A extends AggsQuery>(search: {
|
|
31
|
+
body: q.Search<T, A>;
|
|
32
|
+
index?: string;
|
|
33
|
+
}, options?: TransportRequestOptions): Promise<q.SearchResponse<T, A>>;
|
|
34
|
+
msearchDictTS<T>(search: {
|
|
35
|
+
[k: string]: any;
|
|
36
|
+
}, index?: string): Promise<void>;
|
|
37
|
+
msearchTS<T, A extends AggsQuery>(msearchTs: q.Search<T, A>[], index?: string, options?: TransportRequestOptions): Promise<q.SearchResponse<T, A>[]>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypescriptOSProxyClient = exports.IGNORE_ATTS = void 0;
|
|
4
|
+
const _ = require("lodash");
|
|
5
|
+
const search_1 = require("./search");
|
|
6
|
+
exports.IGNORE_ATTS = ["_source", "response", "index"];
|
|
7
|
+
class TypescriptOSProxyClient {
|
|
8
|
+
constructor(esClient) {
|
|
9
|
+
this.esClient = esClient;
|
|
10
|
+
}
|
|
11
|
+
async countTs(search, options) {
|
|
12
|
+
return this.esClient.count({
|
|
13
|
+
index: search.body.index || search.index,
|
|
14
|
+
body: _.omit(search.body, exports.IGNORE_ATTS)
|
|
15
|
+
}, options)
|
|
16
|
+
.then(resp => {
|
|
17
|
+
return resp.body;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async searchTS(search, options) {
|
|
21
|
+
return this.esClient.search({
|
|
22
|
+
index: search.body.index || search.index,
|
|
23
|
+
body: _.omit(search.body, exports.IGNORE_ATTS)
|
|
24
|
+
}, options)
|
|
25
|
+
.then(resp => {
|
|
26
|
+
search.body.response = resp.body;
|
|
27
|
+
return search.body.response;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async msearchDictTS(search, index) {
|
|
31
|
+
const msearch = search;
|
|
32
|
+
const entries = Object.entries(msearch);
|
|
33
|
+
const queries = entries.map(([, value]) => value);
|
|
34
|
+
const keys = entries.map(([key,]) => key);
|
|
35
|
+
await this.msearchTS(queries, index);
|
|
36
|
+
keys.forEach((key, i) => {
|
|
37
|
+
search[key] = queries[i];
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async msearchTS(msearchTs, index, options) {
|
|
41
|
+
const msearch = msearchTs.flatMap(s => [{
|
|
42
|
+
index: s.index || index
|
|
43
|
+
}, _.omit(s, exports.IGNORE_ATTS)]);
|
|
44
|
+
const responses = (await this.esClient.msearch({ body: msearch, index }, options)).body.responses;
|
|
45
|
+
responses.forEach((resp, i) => {
|
|
46
|
+
msearchTs[i].response = resp;
|
|
47
|
+
});
|
|
48
|
+
return msearchTs.map((search, i) => new search_1.ResponseParser(search).parseSearchResponse(responses[i]));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.TypescriptOSProxyClient = TypescriptOSProxyClient;
|