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
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { ShardStatistics } from "@opensearch-project/opensearch/api/_types/_common";
|
|
2
|
+
import { TotalHits } from "@opensearch-project/opensearch/api/_types/_core.search";
|
|
3
|
+
import { RequireAtLeastOne, RequireExactlyOne } from "type-fest";
|
|
4
|
+
import { AggTypeDictionaryRecursive, AggsQuery } from "./aggInput";
|
|
5
|
+
import { AggTypeResponseDictionary2 } from "./aggOutput";
|
|
6
|
+
import * as att from "./attributes";
|
|
7
|
+
import { NumberField } from "./fields";
|
|
8
|
+
import * as f from "./filters";
|
|
9
|
+
import * as m from "./match";
|
|
10
|
+
/**
|
|
11
|
+
* Represents a document
|
|
12
|
+
*/
|
|
13
|
+
export type Document<T> = {
|
|
14
|
+
_index: string;
|
|
15
|
+
_id: string;
|
|
16
|
+
_score: number;
|
|
17
|
+
_source: T;
|
|
18
|
+
sort?: any[];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Represents (Hits|Search Results)
|
|
22
|
+
*/
|
|
23
|
+
export type Hits<T> = {
|
|
24
|
+
"total": number & TotalHits;
|
|
25
|
+
"max_score": any;
|
|
26
|
+
"hits": Document<T>[];
|
|
27
|
+
};
|
|
28
|
+
export type Source<T> = {
|
|
29
|
+
includes?: att.AnyAttribute<T>[];
|
|
30
|
+
excludes?: att.AnyAttribute<T>[];
|
|
31
|
+
};
|
|
32
|
+
export type BooleanStatement<T> = {
|
|
33
|
+
should?: f.FilterStatement<T>[] | f.FilterStatement<T>;
|
|
34
|
+
filter?: f.FilterStatement<T>[] | f.FilterStatement<T>;
|
|
35
|
+
must?: f.FilterStatement<T>[] | f.FilterStatement<T>;
|
|
36
|
+
must_not?: f.FilterStatement<T>[] | f.FilterStatement<T>;
|
|
37
|
+
minimum_should_match?: number;
|
|
38
|
+
};
|
|
39
|
+
export type Boosting<T> = {
|
|
40
|
+
positive: {
|
|
41
|
+
match: m.Match<T>;
|
|
42
|
+
};
|
|
43
|
+
negative: {
|
|
44
|
+
match: m.Match<T>;
|
|
45
|
+
};
|
|
46
|
+
negative_boost: number;
|
|
47
|
+
};
|
|
48
|
+
export type ConstanScore<T> = {
|
|
49
|
+
filter: f.FilterStatement<T>;
|
|
50
|
+
boost: number;
|
|
51
|
+
};
|
|
52
|
+
export type DisjointMatrix<T> = {
|
|
53
|
+
queries: m.Match<T>[];
|
|
54
|
+
};
|
|
55
|
+
export type FunctionScore<T> = {
|
|
56
|
+
weight: number;
|
|
57
|
+
query: m.Match<T>;
|
|
58
|
+
} & RequireAtLeastOne<{
|
|
59
|
+
random_score: {
|
|
60
|
+
seed: number;
|
|
61
|
+
} & NumberField<T>;
|
|
62
|
+
field_value_factor: {
|
|
63
|
+
factor: number;
|
|
64
|
+
modifier: "log" | "log1p" | "log2p" | "ln" | "ln1p" | "ln2p" | "reciprocal" | "square" | "sqrt" | "none";
|
|
65
|
+
missing?: number;
|
|
66
|
+
} & NumberField<T>;
|
|
67
|
+
script_score: {
|
|
68
|
+
script: string | {
|
|
69
|
+
params: {
|
|
70
|
+
[k: string]: number;
|
|
71
|
+
};
|
|
72
|
+
source: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
exp: {
|
|
76
|
+
[a in att.AnyAttribute<T>]: {
|
|
77
|
+
origin?: string;
|
|
78
|
+
offset?: string;
|
|
79
|
+
scale?: string;
|
|
80
|
+
decay?: number;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
}>;
|
|
84
|
+
export type IDs = {
|
|
85
|
+
ids: {
|
|
86
|
+
values: string[];
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
export type Nested<T> = {
|
|
90
|
+
path: string;
|
|
91
|
+
query: OSQuery<T>;
|
|
92
|
+
ignore_unmapped?: boolean;
|
|
93
|
+
score_mode?: string;
|
|
94
|
+
boost?: number;
|
|
95
|
+
inner_hits?: {
|
|
96
|
+
ignore_unmapped?: boolean;
|
|
97
|
+
from?: number;
|
|
98
|
+
size?: number;
|
|
99
|
+
version?: boolean;
|
|
100
|
+
seq_no_primary_term?: false;
|
|
101
|
+
explain?: false;
|
|
102
|
+
track_scores?: false;
|
|
103
|
+
_source?: Source<T>;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Query to select a sub-set of documents
|
|
108
|
+
*/
|
|
109
|
+
export type OSQuery<T> = {
|
|
110
|
+
function_score?: FunctionScore<T>;
|
|
111
|
+
constant_score?: ConstanScore<T>;
|
|
112
|
+
boosting?: Boosting<T>;
|
|
113
|
+
match_all?: {};
|
|
114
|
+
bool?: BooleanStatement<T>;
|
|
115
|
+
nested?: Nested<T>;
|
|
116
|
+
dis_max?: DisjointMatrix<T>;
|
|
117
|
+
match_phrase?: m.MatchPhrase<T>;
|
|
118
|
+
match?: m.Match<T>;
|
|
119
|
+
} & Partial<f.FilterStatement<T>>;
|
|
120
|
+
export type AggsExp<T, A extends AggsQuery> = {
|
|
121
|
+
[K in keyof A]: AggTypeDictionaryRecursive<T, A[K]["agg"], A[K]["aggs"]>;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Search query with description of the aggs, as well as the response
|
|
125
|
+
*/
|
|
126
|
+
export type Search<T, A extends AggsQuery> = {
|
|
127
|
+
/** Aggs query */
|
|
128
|
+
aggs?: AggsExp<T, A>;
|
|
129
|
+
docvalue_fields?: att.AnyAttribute<T>[];
|
|
130
|
+
/** Query used for search */
|
|
131
|
+
query?: OSQuery<T>;
|
|
132
|
+
/** Subset of attributes used for search */
|
|
133
|
+
_source?: Source<T> | boolean;
|
|
134
|
+
indices_boost?: {
|
|
135
|
+
[a: string]: number;
|
|
136
|
+
}[];
|
|
137
|
+
min_score?: number;
|
|
138
|
+
seq_no_primary_term?: boolean;
|
|
139
|
+
terminate_after?: number;
|
|
140
|
+
/** Number of documents to return in search */
|
|
141
|
+
size?: number;
|
|
142
|
+
stats?: string[];
|
|
143
|
+
track_total_hits?: boolean;
|
|
144
|
+
version?: boolean;
|
|
145
|
+
explain?: boolean;
|
|
146
|
+
from?: number;
|
|
147
|
+
timeout?: string;
|
|
148
|
+
stored_fields?: att.AnyAttribute<T>[];
|
|
149
|
+
/** How to sort */
|
|
150
|
+
sort?: RequireExactlyOne<{
|
|
151
|
+
[key in att.AnyAttribute<T>]: {
|
|
152
|
+
order?: "desc" | "asc";
|
|
153
|
+
missing?: "_first" | "_last";
|
|
154
|
+
nested_filter?: OSQuery<T>;
|
|
155
|
+
nested_path?: string;
|
|
156
|
+
mode?: "min" | "max" | "avg" | "sum";
|
|
157
|
+
};
|
|
158
|
+
}>[];
|
|
159
|
+
search_after?: any[];
|
|
160
|
+
/** Response which will be populated after searching */
|
|
161
|
+
response?: SearchResponse<T, A>;
|
|
162
|
+
/** Index used for the search */
|
|
163
|
+
index?: string;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Type 'ResponseItem' is not assignable to type 'SearchResponse<T, A>'.
|
|
167
|
+
Type 'MultiSearchItem' is not assignable to type 'SearchResponse<T, A>'.
|
|
168
|
+
Types of property '"_shards"' are incompatible.
|
|
169
|
+
Type 'ShardStatistics' is not assignable to type 'ShardsHitResult'.
|
|
170
|
+
Property '"skipped"' is optional in type 'ShardStatistics' but required in type 'ShardsHitResult'.
|
|
171
|
+
*/
|
|
172
|
+
/**
|
|
173
|
+
* Details of the Shards Hit
|
|
174
|
+
*/
|
|
175
|
+
/**
|
|
176
|
+
* The search response JSON
|
|
177
|
+
*/
|
|
178
|
+
export type SearchResponse<T, A extends AggsQuery> = {
|
|
179
|
+
"took": number;
|
|
180
|
+
"timed_out": boolean;
|
|
181
|
+
"_shards": ShardStatistics;
|
|
182
|
+
"hits": Hits<T>;
|
|
183
|
+
"aggregations"?: {
|
|
184
|
+
[K in keyof A]: AggTypeResponseDictionary2<T, A[K]["agg"], A[K]["aggs"]>;
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Class to parse Reponse JSON to it's corresponding type
|
|
189
|
+
*/
|
|
190
|
+
export declare class ResponseParser<T, A extends AggsQuery> {
|
|
191
|
+
search: Search<T, A>;
|
|
192
|
+
constructor(search: Search<T, A>);
|
|
193
|
+
parseSearchResponse: (response: any) => SearchResponse<T, A>;
|
|
194
|
+
}
|
package/dist/search.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseParser = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Class to parse Reponse JSON to it's corresponding type
|
|
6
|
+
*/
|
|
7
|
+
class ResponseParser {
|
|
8
|
+
constructor(search) {
|
|
9
|
+
this.parseSearchResponse = (response) => response;
|
|
10
|
+
this.search = search;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.ResponseParser = ResponseParser;
|
package/dist/testUtil.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeClientWithEndpoint = void 0;
|
|
4
|
+
const credential_provider_node_1 = require("@aws-sdk/credential-provider-node");
|
|
5
|
+
const os = require("@opensearch-project/opensearch");
|
|
6
|
+
const aws_1 = require("@opensearch-project/opensearch/aws");
|
|
7
|
+
const makeClientWithEndpoint = async (endpoint) => {
|
|
8
|
+
return new os.Client({
|
|
9
|
+
...(0, aws_1.AwsSigv4Signer)({
|
|
10
|
+
region: process.env.AWS_REGION || "ap-southeast-2",
|
|
11
|
+
service: 'es',
|
|
12
|
+
getCredentials: () => {
|
|
13
|
+
const credentialsProvider = (0, credential_provider_node_1.defaultProvider)();
|
|
14
|
+
return credentialsProvider();
|
|
15
|
+
},
|
|
16
|
+
}),
|
|
17
|
+
node: `https://${endpoint || process.env.ES_ENDPOINT || "search-alertops-qeosrpbxjt4uyywic5fycm4pg4.ap-southeast-2.es.amazonaws.com"}`
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
exports.makeClientWithEndpoint = makeClientWithEndpoint;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export interface Ecommerce {
|
|
2
|
+
category: string[];
|
|
3
|
+
currency: string;
|
|
4
|
+
customer_first_name: string;
|
|
5
|
+
customer_full_name: string;
|
|
6
|
+
customer_gender: string;
|
|
7
|
+
customer_id: number;
|
|
8
|
+
customer_last_name: string;
|
|
9
|
+
customer_phone: string;
|
|
10
|
+
day_of_week: string;
|
|
11
|
+
day_of_week_i: number;
|
|
12
|
+
email: string;
|
|
13
|
+
manufacturer: string[];
|
|
14
|
+
order_date: Date;
|
|
15
|
+
order_id: number;
|
|
16
|
+
products: Product[];
|
|
17
|
+
sku: string[];
|
|
18
|
+
taxful_total_price: number;
|
|
19
|
+
taxless_total_price: number;
|
|
20
|
+
total_quantity: number;
|
|
21
|
+
total_unique_products: number;
|
|
22
|
+
type: string;
|
|
23
|
+
user: string;
|
|
24
|
+
geoip: Geoip;
|
|
25
|
+
event: Event;
|
|
26
|
+
}
|
|
27
|
+
export interface Event {
|
|
28
|
+
dataset: string;
|
|
29
|
+
}
|
|
30
|
+
export interface Geoip {
|
|
31
|
+
country_iso_code: string;
|
|
32
|
+
location: Location;
|
|
33
|
+
region_name: string;
|
|
34
|
+
continent_name: string;
|
|
35
|
+
city_name: string;
|
|
36
|
+
}
|
|
37
|
+
export interface Location {
|
|
38
|
+
lon: number;
|
|
39
|
+
lat: number;
|
|
40
|
+
}
|
|
41
|
+
export interface Product {
|
|
42
|
+
base_price: number;
|
|
43
|
+
discount_percentage: number;
|
|
44
|
+
quantity: number;
|
|
45
|
+
manufacturer: string;
|
|
46
|
+
tax_amount: number;
|
|
47
|
+
product_id: number;
|
|
48
|
+
category: string;
|
|
49
|
+
sku: string;
|
|
50
|
+
taxless_price: number;
|
|
51
|
+
unit_discount_amount: number;
|
|
52
|
+
min_price: number;
|
|
53
|
+
_id: string;
|
|
54
|
+
discount_amount: number;
|
|
55
|
+
created_on: Date;
|
|
56
|
+
product_name: string;
|
|
57
|
+
price: number;
|
|
58
|
+
taxful_price: number;
|
|
59
|
+
base_unit_price: number;
|
|
60
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface Flight {
|
|
2
|
+
FlightNum: string;
|
|
3
|
+
DestCountry: string;
|
|
4
|
+
OriginWeather: string;
|
|
5
|
+
OriginCityName: string;
|
|
6
|
+
AvgTicketPrice: number;
|
|
7
|
+
DistanceMiles: number;
|
|
8
|
+
FlightDelay: boolean;
|
|
9
|
+
DestWeather: string;
|
|
10
|
+
Dest: string;
|
|
11
|
+
FlightDelayType: string;
|
|
12
|
+
OriginCountry: string;
|
|
13
|
+
dayOfWeek: number;
|
|
14
|
+
DistanceKilometers: number;
|
|
15
|
+
timestamp: Date;
|
|
16
|
+
DestLocation: Location;
|
|
17
|
+
DestAirportID: string;
|
|
18
|
+
Carrier: string;
|
|
19
|
+
Cancelled: boolean;
|
|
20
|
+
FlightTimeMin: number;
|
|
21
|
+
Origin: string;
|
|
22
|
+
OriginLocation: Location;
|
|
23
|
+
DestRegion: string;
|
|
24
|
+
OriginAirportID: string;
|
|
25
|
+
OriginRegion: string;
|
|
26
|
+
DestCityName: string;
|
|
27
|
+
FlightTimeHour: number;
|
|
28
|
+
FlightDelayMin: number;
|
|
29
|
+
}
|
|
30
|
+
export interface Location {
|
|
31
|
+
lat: string;
|
|
32
|
+
lon: string;
|
|
33
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface ServerLog {
|
|
2
|
+
agent: string;
|
|
3
|
+
bytes: number;
|
|
4
|
+
clientip: string;
|
|
5
|
+
extension: string;
|
|
6
|
+
geo: Geo;
|
|
7
|
+
host: string;
|
|
8
|
+
index: string;
|
|
9
|
+
ip: string;
|
|
10
|
+
machine: Machine;
|
|
11
|
+
memory: number;
|
|
12
|
+
message: string;
|
|
13
|
+
phpmemory: null;
|
|
14
|
+
referer: string;
|
|
15
|
+
request: string;
|
|
16
|
+
response: string;
|
|
17
|
+
tags: string[];
|
|
18
|
+
timestamp: Date;
|
|
19
|
+
"@timestamp": Date;
|
|
20
|
+
url: string;
|
|
21
|
+
utc_time: Date;
|
|
22
|
+
event: Event;
|
|
23
|
+
}
|
|
24
|
+
export interface Event {
|
|
25
|
+
dataset: string;
|
|
26
|
+
}
|
|
27
|
+
export interface Geo {
|
|
28
|
+
srcdest: string;
|
|
29
|
+
src: string;
|
|
30
|
+
dest: string;
|
|
31
|
+
coordinates: Coordinates;
|
|
32
|
+
}
|
|
33
|
+
export interface Coordinates {
|
|
34
|
+
lat: number;
|
|
35
|
+
lon: number;
|
|
36
|
+
}
|
|
37
|
+
export interface Machine {
|
|
38
|
+
ram: number;
|
|
39
|
+
os: string;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|