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,174 @@
|
|
|
1
|
+
import { BooleanAtt } from ".";
|
|
2
|
+
import { NumberAtt, DateAtt, KeyWord, StringAtt, AnyAttribute, TextOrKeywordAtt } from "./attributes";
|
|
3
|
+
import * as att from "./attributes";
|
|
4
|
+
import { BooleanStatement } from "./search";
|
|
5
|
+
import type { RequireExactlyOne } from 'type-fest';
|
|
6
|
+
export type RangeDefaults<A> = {
|
|
7
|
+
gte?: A;
|
|
8
|
+
lte?: A;
|
|
9
|
+
gt?: A;
|
|
10
|
+
lt?: A;
|
|
11
|
+
};
|
|
12
|
+
export type Range<T, B extends string, R extends RangeDefaults<T>> = RequireExactlyOne<{
|
|
13
|
+
[key in B]: R;
|
|
14
|
+
}>;
|
|
15
|
+
export type NumberRange<T> = Range<number, NumberAtt<T>, RangeDefaults<number>>;
|
|
16
|
+
export type DateRangeStatement = {
|
|
17
|
+
gte?: Date | string;
|
|
18
|
+
lte?: Date | string;
|
|
19
|
+
gt?: Date | string;
|
|
20
|
+
lt?: Date | string;
|
|
21
|
+
time_zone?: string;
|
|
22
|
+
format?: string;
|
|
23
|
+
execution?: string;
|
|
24
|
+
};
|
|
25
|
+
export type DateRange<T> = RequireExactlyOne<{
|
|
26
|
+
[key in DateAtt<T>]: DateRangeStatement;
|
|
27
|
+
}>;
|
|
28
|
+
export type RangeStatement<T> = {
|
|
29
|
+
"range": NumberRange<T> | DateRange<T>;
|
|
30
|
+
};
|
|
31
|
+
export type ExistsStatement<T> = {
|
|
32
|
+
"exists": {
|
|
33
|
+
"field": AnyAttribute<T>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type PrefixStatement<T> = {
|
|
37
|
+
"prefix": RequireExactlyOne<{
|
|
38
|
+
[key in TextOrKeywordAtt<T>]: {
|
|
39
|
+
value: string;
|
|
40
|
+
boost?: number;
|
|
41
|
+
};
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
export type WildCardStatement<T> = {
|
|
45
|
+
"wildcard": RequireExactlyOne<{
|
|
46
|
+
[key in TextOrKeywordAtt<T>]: {
|
|
47
|
+
value: string;
|
|
48
|
+
boost?: number;
|
|
49
|
+
};
|
|
50
|
+
}>;
|
|
51
|
+
};
|
|
52
|
+
export type RegexpStatement<T> = {
|
|
53
|
+
"regexp": RequireExactlyOne<{
|
|
54
|
+
[key in TextOrKeywordAtt<T>]: {
|
|
55
|
+
value: string;
|
|
56
|
+
flags?: number;
|
|
57
|
+
max_determinized_states?: number;
|
|
58
|
+
};
|
|
59
|
+
}>;
|
|
60
|
+
};
|
|
61
|
+
export type GeoBoundingBox = {
|
|
62
|
+
geo_bounding_box: {
|
|
63
|
+
point: {
|
|
64
|
+
top_left: {
|
|
65
|
+
lat: number;
|
|
66
|
+
lon: number;
|
|
67
|
+
};
|
|
68
|
+
bottom_right: {
|
|
69
|
+
lat: number;
|
|
70
|
+
lon: number;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export type XYShape<T> = {
|
|
76
|
+
xy_shape: {
|
|
77
|
+
geometry: {
|
|
78
|
+
shape: {
|
|
79
|
+
type: "envelope";
|
|
80
|
+
coordinates: [number, number][];
|
|
81
|
+
};
|
|
82
|
+
relation: "INTERSECTS" | "DISJOINT" | "WITHIN" | "CONTAINS";
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
export type FuzzyStatement<T> = {
|
|
87
|
+
fuzzy: RequireExactlyOne<{
|
|
88
|
+
[a in att.StringAtt<T>]: {
|
|
89
|
+
value: string;
|
|
90
|
+
boost?: number;
|
|
91
|
+
fuzziness?: number;
|
|
92
|
+
max_expansions?: number;
|
|
93
|
+
prefix_length?: number;
|
|
94
|
+
rewrite?: string;
|
|
95
|
+
transpositions: boolean;
|
|
96
|
+
};
|
|
97
|
+
}>;
|
|
98
|
+
};
|
|
99
|
+
export type Match<A extends string, V> = {
|
|
100
|
+
"match": {
|
|
101
|
+
[k in keyof RequireExactlyOne<{
|
|
102
|
+
[key in A]: V;
|
|
103
|
+
}>]: {
|
|
104
|
+
query: string;
|
|
105
|
+
auto_generate_synonyms_phrase_query?: boolean;
|
|
106
|
+
analyzer?: string;
|
|
107
|
+
boost?: number;
|
|
108
|
+
enable_position_increments?: boolean;
|
|
109
|
+
fuzziness?: string;
|
|
110
|
+
fuzzy_rewrite?: string;
|
|
111
|
+
fuzzy_transpositions?: boolean;
|
|
112
|
+
lenient?: boolean;
|
|
113
|
+
max_expansions?: number;
|
|
114
|
+
minimum_should_match?: number;
|
|
115
|
+
operator?: string;
|
|
116
|
+
prefix_length?: number;
|
|
117
|
+
zero_terms_query?: string;
|
|
118
|
+
} | string;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
export type MatchKeyword<T> = Match<KeyWord<T>, string>;
|
|
122
|
+
export type MatchString<T> = Match<StringAtt<T>, string>;
|
|
123
|
+
export type MatchStatement<T> = MatchKeyword<T> | MatchString<T>;
|
|
124
|
+
export type Term<A extends string, V> = {
|
|
125
|
+
"term": RequireExactlyOne<{
|
|
126
|
+
[key in A]: V;
|
|
127
|
+
}>;
|
|
128
|
+
};
|
|
129
|
+
export type TermKeyword<T> = Term<KeyWord<T>, string>;
|
|
130
|
+
export type TermString<T> = Term<StringAtt<T>, string>;
|
|
131
|
+
export type TermNumber<T> = Term<NumberAtt<T>, number>;
|
|
132
|
+
export type TermBoolean<T> = Term<BooleanAtt<T>, boolean>;
|
|
133
|
+
export type TermDate<T> = Term<DateAtt<T>, Date>;
|
|
134
|
+
export type TermStatement<T> = TermKeyword<T> | TermString<T> | TermDate<T> | TermNumber<T> | TermBoolean<T>;
|
|
135
|
+
export type Terms<A extends string, V> = {
|
|
136
|
+
"terms": RequireExactlyOne<{
|
|
137
|
+
[key in A]: V[];
|
|
138
|
+
}>;
|
|
139
|
+
};
|
|
140
|
+
export type TermsKeyword<T> = Terms<KeyWord<T>, string>;
|
|
141
|
+
export type TermsString<T> = Terms<StringAtt<T>, string>;
|
|
142
|
+
export type TermsNumber<T> = Terms<NumberAtt<T>, number>;
|
|
143
|
+
export type TermsDate<T> = Terms<DateAtt<T>, Date>;
|
|
144
|
+
export type TermsBoolean<T> = Terms<BooleanAtt<T>, boolean>;
|
|
145
|
+
export type MoreLikeThisStatement<T> = {
|
|
146
|
+
/** Specify the fields to compare */
|
|
147
|
+
"fields"?: TermsString<T>[];
|
|
148
|
+
"like"?: string;
|
|
149
|
+
/** Minimum term frequency in the source document */
|
|
150
|
+
"min_term_freq"?: number;
|
|
151
|
+
/** Maximum number of query terms to use */
|
|
152
|
+
"max_query_terms"?: number;
|
|
153
|
+
/** Minimum number of documents in which a term should appear to be considered. */
|
|
154
|
+
min_doc_freq: number;
|
|
155
|
+
/** Maximum number of documents in which a term may appear. */
|
|
156
|
+
max_doc_freq: number;
|
|
157
|
+
/** Minimum word length below which terms will be ignored. */
|
|
158
|
+
min_word_length: number;
|
|
159
|
+
/** Maximum word length above which terms will be ignored. */
|
|
160
|
+
max_word_length: number;
|
|
161
|
+
};
|
|
162
|
+
export type MoreLikeThis<T> = {
|
|
163
|
+
"more_like_this": MoreLikeThisStatement<T>;
|
|
164
|
+
};
|
|
165
|
+
export type TermsStatement<T> = TermsKeyword<T> | TermsString<T> | TermsNumber<T> | TermsDate<T> | TermsBoolean<T>;
|
|
166
|
+
export type FilterStatement<T> = WildCardStatement<T> | RegexpStatement<T> | PrefixStatement<T> | ExistsStatement<T> | RangeStatement<T> | TermStatement<T> | TermsStatement<T> | MatchStatement<T> | BoolStatement<T> | AndStatement<T> | GeoBoundingBox | XYShape<T> | FuzzyStatement<T> | MoreLikeThis<T>;
|
|
167
|
+
export type BoolStatement<T> = {
|
|
168
|
+
bool: BooleanStatement<T>;
|
|
169
|
+
};
|
|
170
|
+
export type AndStatement<T> = {
|
|
171
|
+
and: {
|
|
172
|
+
filters: FilterStatement<T>;
|
|
173
|
+
};
|
|
174
|
+
};
|
package/dist/filters.js
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.query = void 0;
|
|
18
|
+
__exportStar(require("./typescriptOS"), exports);
|
|
19
|
+
__exportStar(require("./search"), exports);
|
|
20
|
+
__exportStar(require("./aggInput"), exports);
|
|
21
|
+
__exportStar(require("./attributes"), exports);
|
|
22
|
+
__exportStar(require("./attributes"), exports);
|
|
23
|
+
__exportStar(require("./filters"), exports);
|
|
24
|
+
exports.query = require("./query");
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function info(m: any): void;
|
package/dist/logger.js
ADDED
package/dist/match.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RequireExactlyOne } from "type-fest";
|
|
2
|
+
import * as att from "./attributes";
|
|
3
|
+
export type MatchRaw<T> = RequireExactlyOne<{
|
|
4
|
+
[key in att.AnyAttribute<T>]: string;
|
|
5
|
+
}>;
|
|
6
|
+
export type MatchQuery<T> = RequireExactlyOne<{
|
|
7
|
+
[key in att.AnyAttribute<T>]: {
|
|
8
|
+
query: string;
|
|
9
|
+
operator: string;
|
|
10
|
+
minimum_should_match?: number;
|
|
11
|
+
analyzer?: string;
|
|
12
|
+
zero_terms_query?: string;
|
|
13
|
+
fuzziness?: string;
|
|
14
|
+
prefix_length?: string;
|
|
15
|
+
fuzzy_transpositions?: boolean;
|
|
16
|
+
auto_generate_synonyms_phrase_query?: boolean;
|
|
17
|
+
boost?: number;
|
|
18
|
+
enable_position_increments?: boolean;
|
|
19
|
+
fuzzy_rewrite?: string;
|
|
20
|
+
lenient?: boolean;
|
|
21
|
+
max_expansions?: number;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
export type Match<T> = MatchRaw<T> | MatchQuery<T>;
|
|
25
|
+
export type MatchPhrase<T> = RequireExactlyOne<{
|
|
26
|
+
[key in att.TextOrKeywordAtt<T>]: string;
|
|
27
|
+
}>;
|
package/dist/match.js
ADDED
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FilterStatement } from "./filters";
|
|
2
|
+
export declare function negate<T>(filter: FilterStatement<T>): FilterStatement<T>;
|
|
3
|
+
export declare function atLeast<T>(filters: FilterStatement<T>[], minShouldMatch: number): FilterStatement<T>;
|
|
4
|
+
export declare const any: <T>(filters: FilterStatement<T>[]) => FilterStatement<T>;
|
|
5
|
+
export declare const all: <T>(filters: FilterStatement<T>[]) => FilterStatement<T>;
|
|
6
|
+
export declare const none: <T>(filters: FilterStatement<T>[]) => FilterStatement<T>;
|
package/dist/query.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.none = exports.all = exports.any = exports.atLeast = exports.negate = void 0;
|
|
4
|
+
function negate(filter) {
|
|
5
|
+
return {
|
|
6
|
+
"bool": {
|
|
7
|
+
"must_not": [
|
|
8
|
+
filter
|
|
9
|
+
]
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.negate = negate;
|
|
14
|
+
function atLeast(filters, minShouldMatch) {
|
|
15
|
+
const anyMatch = {
|
|
16
|
+
"bool": {
|
|
17
|
+
"should": filters,
|
|
18
|
+
"minimum_should_match": minShouldMatch
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return anyMatch;
|
|
22
|
+
}
|
|
23
|
+
exports.atLeast = atLeast;
|
|
24
|
+
const any = (filters) => atLeast(filters, 1);
|
|
25
|
+
exports.any = any;
|
|
26
|
+
const all = (filters) => ({
|
|
27
|
+
"bool": {
|
|
28
|
+
"filter": filters
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
exports.all = all;
|
|
32
|
+
const none = (filters) => ({
|
|
33
|
+
"bool": {
|
|
34
|
+
"must_not": filters
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
exports.none = none;
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.queries = void 0;
|
|
4
|
+
const typescriptOS_1 = require("./typescriptOS");
|
|
5
|
+
const search_1 = require("./search");
|
|
6
|
+
const testUtil_1 = require("./testUtil");
|
|
7
|
+
const INDEX_LOGS = "opensearch_dashboards_sample_data_logs";
|
|
8
|
+
var esClient;
|
|
9
|
+
var tsClient;
|
|
10
|
+
jest.setTimeout(20000);
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
esClient = await (0, testUtil_1.makeClientWithEndpoint)();
|
|
13
|
+
tsClient = new typescriptOS_1.TypescriptOSProxyClient(esClient);
|
|
14
|
+
});
|
|
15
|
+
const countAll = {
|
|
16
|
+
"query": {
|
|
17
|
+
"match_all": {}
|
|
18
|
+
},
|
|
19
|
+
"aggs": {
|
|
20
|
+
"total": {
|
|
21
|
+
"value_count": {
|
|
22
|
+
"field": "_id"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"size": 0
|
|
27
|
+
};
|
|
28
|
+
const exampleTopHitMax = {
|
|
29
|
+
"size": 0,
|
|
30
|
+
"aggs": {
|
|
31
|
+
"agents": {
|
|
32
|
+
"terms": {
|
|
33
|
+
"field": "agent.keyword",
|
|
34
|
+
},
|
|
35
|
+
"aggs": {
|
|
36
|
+
"maxValue": {
|
|
37
|
+
"max": {
|
|
38
|
+
"field": "@timestamp"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"maxHits": {
|
|
42
|
+
"top_hits": {
|
|
43
|
+
"size": 1,
|
|
44
|
+
"sort": [
|
|
45
|
+
{
|
|
46
|
+
"@timestamp": {
|
|
47
|
+
"order": "desc"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"minValue": {
|
|
54
|
+
"min": {
|
|
55
|
+
"field": "@timestamp"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"minHits": {
|
|
59
|
+
"top_hits": {
|
|
60
|
+
"size": 1,
|
|
61
|
+
"sort": [
|
|
62
|
+
{
|
|
63
|
+
"@timestamp": {
|
|
64
|
+
"order": "asc"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
query: {
|
|
74
|
+
"match_all": {}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const searchMatchAll = {
|
|
78
|
+
query: {
|
|
79
|
+
"match_all": {}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const searchExample = {
|
|
83
|
+
index: INDEX_LOGS,
|
|
84
|
+
_source: {
|
|
85
|
+
includes: [
|
|
86
|
+
"bytes",
|
|
87
|
+
"utc_time"
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
query: {
|
|
91
|
+
bool: {
|
|
92
|
+
must: [
|
|
93
|
+
{
|
|
94
|
+
"terms": {
|
|
95
|
+
"agent.keyword": [
|
|
96
|
+
"Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110421 Firefox/6.0a1",
|
|
97
|
+
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)",
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"range": {
|
|
103
|
+
"@timestamp": {
|
|
104
|
+
"lte": "2025-01-25T03:41:11.215Z",
|
|
105
|
+
"gte": new Date("2005-01-25T03:41:11.215Z")
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
"minimum_should_match": 2,
|
|
111
|
+
"should": [
|
|
112
|
+
{
|
|
113
|
+
"term": {
|
|
114
|
+
"tags.keyword": "login"
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"term": {
|
|
119
|
+
"tags.keyword": "success"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
aggs: {
|
|
126
|
+
"exampleDateHist": {
|
|
127
|
+
"date_histogram": {
|
|
128
|
+
"interval": "3d",
|
|
129
|
+
"field": "timestamp"
|
|
130
|
+
},
|
|
131
|
+
"aggs": {
|
|
132
|
+
"agentTerms": {
|
|
133
|
+
"terms": {
|
|
134
|
+
"field": "agent.keyword",
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
"adjacency": {
|
|
140
|
+
"adjacency_matrix": {
|
|
141
|
+
"filters": {
|
|
142
|
+
"linux": {
|
|
143
|
+
"match": {
|
|
144
|
+
"agent.keyword": "Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110421 Firefox/6.0a1",
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
"windows": {
|
|
148
|
+
"match": {
|
|
149
|
+
"agent.keyword": "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)",
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
"test": {
|
|
156
|
+
"terms": {
|
|
157
|
+
"field": "agent.keyword"
|
|
158
|
+
},
|
|
159
|
+
"aggs": {
|
|
160
|
+
"innerTest": {
|
|
161
|
+
"extended_stats": {
|
|
162
|
+
"field": "bytes"
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
"somethingMore": {
|
|
166
|
+
"terms": {
|
|
167
|
+
"field": "referer.keyword"
|
|
168
|
+
},
|
|
169
|
+
"aggs": {
|
|
170
|
+
"maxValue": {
|
|
171
|
+
"max": {
|
|
172
|
+
"field": "@timestamp"
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
"maxHits": {
|
|
176
|
+
"top_hits": {
|
|
177
|
+
"size": 2,
|
|
178
|
+
"sort": [
|
|
179
|
+
{
|
|
180
|
+
"@timestamp": {
|
|
181
|
+
"order": "desc"
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
]
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
"minValue": {
|
|
188
|
+
"min": {
|
|
189
|
+
"field": "@timestamp"
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
"minHits": {
|
|
193
|
+
"top_hits": {
|
|
194
|
+
"size": 1,
|
|
195
|
+
"sort": [
|
|
196
|
+
{
|
|
197
|
+
"@timestamp": {
|
|
198
|
+
"order": "asc"
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
"size": 10
|
|
210
|
+
};
|
|
211
|
+
exports.queries = [
|
|
212
|
+
{},
|
|
213
|
+
searchExample,
|
|
214
|
+
{},
|
|
215
|
+
searchMatchAll,
|
|
216
|
+
];
|
|
217
|
+
test("normal count", async () => {
|
|
218
|
+
const response = await tsClient.countTs({ body: {}, index: INDEX_LOGS });
|
|
219
|
+
response.count;
|
|
220
|
+
response._shards.total;
|
|
221
|
+
response._shards.failed;
|
|
222
|
+
response._shards.skipped;
|
|
223
|
+
response._shards.successful;
|
|
224
|
+
console.log(JSON.stringify(response, null, 2));
|
|
225
|
+
});
|
|
226
|
+
test("agg count all documents", async () => {
|
|
227
|
+
const response = await tsClient.searchTS({ body: countAll, index: INDEX_LOGS });
|
|
228
|
+
console.log(response.aggregations.total.value);
|
|
229
|
+
console.log(JSON.stringify(response, null, 2));
|
|
230
|
+
});
|
|
231
|
+
test("msearchTS", async () => {
|
|
232
|
+
const response = await tsClient.msearchTS([
|
|
233
|
+
searchExample,
|
|
234
|
+
searchMatchAll,
|
|
235
|
+
], INDEX_LOGS);
|
|
236
|
+
const searchExampleResponse = new search_1.ResponseParser(searchExample).parseSearchResponse(response[0]);
|
|
237
|
+
console.log(JSON.stringify(searchExampleResponse.aggregations.adjacency.buckets, null, 2));
|
|
238
|
+
// console.log(JSON.stringify(response, null, 2))
|
|
239
|
+
});
|
|
240
|
+
const msearch = {
|
|
241
|
+
"searchExample": searchExample,
|
|
242
|
+
"searchMatchAll": searchMatchAll
|
|
243
|
+
};
|
|
244
|
+
test("testRawTypes", async () => {
|
|
245
|
+
await tsClient.msearchDictTS(msearch);
|
|
246
|
+
// console.log(JSON.stringify(msearch.searchExample.response.aggregations.test.buckets, null, 2))
|
|
247
|
+
console.log(JSON.stringify(msearch, null, 2));
|
|
248
|
+
console.log(JSON.stringify(msearch.searchExample.response.aggregations.test.buckets
|
|
249
|
+
.flatMap(b => b.innerTest), null, 2));
|
|
250
|
+
});
|
|
251
|
+
test("searchTS222", async () => {
|
|
252
|
+
const response = await tsClient.searchTS({ body: searchExample, index: INDEX_LOGS });
|
|
253
|
+
console.log(searchExample.response.aggregations.exampleDateHist.buckets.flatMap(b => b.agentTerms.buckets
|
|
254
|
+
.flatMap(t => ({
|
|
255
|
+
"t.key": t.key,
|
|
256
|
+
"t.doc_count": t.doc_count,
|
|
257
|
+
"b.key_as_string": b.key_as_string,
|
|
258
|
+
// "b.key_as_string" : b.key_as_string,
|
|
259
|
+
}))));
|
|
260
|
+
// console.log("OPENSEARCH")
|
|
261
|
+
// console.log(JSON.stringify(searchExample.response.aggregations.test.buckets.map(b => b.doc_count), null, 2))
|
|
262
|
+
// console.log(JSON.stringify(searchExample.response.aggregations.exampleDateHist
|
|
263
|
+
// .buckets.flatMap(b => b.agentTerms
|
|
264
|
+
// .buckets.flatMap(a => ({doc_count : a.doc_count, key : `${b.key}.${a.key}`}))), null, 2))
|
|
265
|
+
});
|
|
266
|
+
test("exampleTopHitMax", async () => {
|
|
267
|
+
const response = await tsClient.searchTS({ body: exampleTopHitMax, index: INDEX_LOGS });
|
|
268
|
+
console.log(JSON.stringify(response.aggregations.agents.buckets.flatMap(agent => ({
|
|
269
|
+
minFromMin: agent.minValue.value_as_string,
|
|
270
|
+
minFromDoc: agent.minHits.hits.hits[0]._source.timestamp,
|
|
271
|
+
minDoc: agent.minHits.hits.hits[0],
|
|
272
|
+
maxFromMin: agent.maxValue.value_as_string,
|
|
273
|
+
maxFromDoc: agent.maxHits.hits.hits[0]._source.timestamp,
|
|
274
|
+
maxDoc: agent.maxHits.hits.hits[0],
|
|
275
|
+
})), null, 2));
|
|
276
|
+
});
|
|
277
|
+
test("single example match and filter", async () => {
|
|
278
|
+
const matchAndFilter = {
|
|
279
|
+
query: {
|
|
280
|
+
"bool": {
|
|
281
|
+
"must": {
|
|
282
|
+
"match": {
|
|
283
|
+
"agent": {
|
|
284
|
+
"query": "Chrome"
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
size: 5
|
|
291
|
+
};
|
|
292
|
+
const response = await tsClient.searchTS({ body: matchAndFilter, index: INDEX_LOGS });
|
|
293
|
+
console.log(JSON.stringify(response, null, 2));
|
|
294
|
+
});
|
|
295
|
+
test("Filter by IDs example", async () => {
|
|
296
|
+
const matchAndFilter = {
|
|
297
|
+
"query": {
|
|
298
|
+
"terms": {
|
|
299
|
+
"_id": ["hello", "abcd-1234"]
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const response = await tsClient.searchTS({ body: matchAndFilter, index: INDEX_LOGS });
|
|
304
|
+
console.log(JSON.stringify(response, null, 2));
|
|
305
|
+
});
|
|
306
|
+
test("Filter by ID example", async () => {
|
|
307
|
+
const matchAndFilter = {
|
|
308
|
+
"query": {
|
|
309
|
+
"term": {
|
|
310
|
+
"_id": "2345"
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
const response = await tsClient.searchTS({ body: matchAndFilter, index: INDEX_LOGS });
|
|
315
|
+
console.log(JSON.stringify(response, null, 2));
|
|
316
|
+
});
|
|
317
|
+
test("multi example match and filter", async () => {
|
|
318
|
+
const matchAndFilter = {
|
|
319
|
+
query: {
|
|
320
|
+
"bool": {
|
|
321
|
+
"must": {
|
|
322
|
+
"match": {
|
|
323
|
+
"agent": {
|
|
324
|
+
"query": "Chrome"
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
"filter": {
|
|
329
|
+
"term": {
|
|
330
|
+
"extension.keyword": "zip"
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
size: 5
|
|
336
|
+
};
|
|
337
|
+
const response = await tsClient.searchTS({ body: matchAndFilter, index: INDEX_LOGS });
|
|
338
|
+
console.log(JSON.stringify(response, null, 2));
|
|
339
|
+
});
|
|
340
|
+
test("multi example match and filter", async () => {
|
|
341
|
+
const matchAndFilter = {
|
|
342
|
+
query: {
|
|
343
|
+
"bool": {
|
|
344
|
+
"must": {
|
|
345
|
+
"match": {
|
|
346
|
+
"agent": "Chrome"
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
"filter": {
|
|
350
|
+
"term": {
|
|
351
|
+
"extension.keyword": "zip"
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
size: 5
|
|
357
|
+
};
|
|
358
|
+
const response = await tsClient.searchTS({ body: matchAndFilter, index: INDEX_LOGS });
|
|
359
|
+
console.log(JSON.stringify(response, null, 2));
|
|
360
|
+
});
|