@opensearch-project/opensearch 2.3.1 → 2.5.0
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/CHANGELOG.md +66 -12
- package/COMPATIBILITY.md +8 -22
- package/MAINTAINERS.md +6 -5
- package/USER_GUIDE.md +34 -3
- package/api/api/http.js +213 -0
- package/api/api/indices.js +1 -1
- package/api/api/security.js +1954 -0
- package/api/index.js +22 -0
- package/api/new.d.ts +902 -0
- package/api/requestParams.d.ts +7 -0
- package/api/utils.js +13 -1
- package/guides/index_lifecycle.md +2 -2
- package/guides/json.md +60 -0
- package/guides/msearch.md +66 -0
- package/guides/search.md +1 -1
- package/index.d.ts +88 -0
- package/lib/Transport.js +3 -2
- package/lib/aws/AwsSigv4Signer.js +11 -1
- package/package.json +13 -7
- package/samples/README.md +14 -0
- package/samples/json.js +75 -0
- package/samples/msearch.js +130 -0
- package/samples/search.js +154 -0
package/api/requestParams.d.ts
CHANGED
|
@@ -750,6 +750,13 @@ export interface GetSource extends Generic {
|
|
|
750
750
|
version_type?: 'internal' | 'external' | 'external_gte' | 'force';
|
|
751
751
|
}
|
|
752
752
|
|
|
753
|
+
export interface HttpParams extends Generic {
|
|
754
|
+
path: string;
|
|
755
|
+
querystring?: Record<string, any>;
|
|
756
|
+
headers?: Record<string, any>;
|
|
757
|
+
body?: Record<string, any> | string | Array<string | Record<string, any>>;
|
|
758
|
+
}
|
|
759
|
+
|
|
753
760
|
export interface Index<T = RequestBody> extends Generic {
|
|
754
761
|
id?: string;
|
|
755
762
|
index: string;
|
package/api/utils.js
CHANGED
|
@@ -40,6 +40,11 @@ function handleError(err, callback) {
|
|
|
40
40
|
return Promise.reject(err);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
function encodePathParam(camelName, snakeName = null) {
|
|
44
|
+
if (camelName == null && snakeName == null) return null;
|
|
45
|
+
return encodeURIComponent(snakeName || camelName);
|
|
46
|
+
}
|
|
47
|
+
|
|
43
48
|
function snakeCaseKeys(acceptedQuerystring, snakeCase, querystring) {
|
|
44
49
|
const target = {};
|
|
45
50
|
const keys = Object.keys(querystring);
|
|
@@ -65,4 +70,11 @@ function normalizeArguments(params, options, callback) {
|
|
|
65
70
|
|
|
66
71
|
function noop() {}
|
|
67
72
|
|
|
68
|
-
module.exports = {
|
|
73
|
+
module.exports = {
|
|
74
|
+
handleError,
|
|
75
|
+
snakeCaseKeys,
|
|
76
|
+
normalizeArguments,
|
|
77
|
+
noop,
|
|
78
|
+
kConfigurationError,
|
|
79
|
+
encodePathParam,
|
|
80
|
+
};
|
|
@@ -139,9 +139,9 @@ client.indices.delete({index: 'movies'})
|
|
|
139
139
|
We can also delete multiple indices at once:
|
|
140
140
|
|
|
141
141
|
```javascript
|
|
142
|
-
client.indices.delete({index: ['movies', 'paintings', 'burner'],
|
|
142
|
+
client.indices.delete({index: ['movies', 'paintings', 'burner'], ignore_unavailable: true,})
|
|
143
143
|
```
|
|
144
|
-
Notice that we are passing `
|
|
144
|
+
Notice that we are passing `ignore_unavailable: true` to the request. This tells the client to ignore throwing error and deleting the index if it doesn't exist. Without it, the above `delete` request will throw an error because the `movies` index has already been deleted in the previous example.
|
|
145
145
|
|
|
146
146
|
## Cleanup
|
|
147
147
|
|
package/guides/json.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Making raw HTTP requests
|
|
2
|
+
|
|
3
|
+
The OpenSearch client implements many high-level REST DSLs that invoke OpenSearch APIs. However, you may find yourself in a situation that requires you to invoke an API that is not supported by the client. In this case, you can use raw HTTP requests to invoke any OpenSearch API. This guide shows you different ways to make custom API calls using the OpenSearch JS client.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
First, create a client instance with the following code to interact with an OpenSearch cluster with default security settings:
|
|
7
|
+
|
|
8
|
+
```javascript
|
|
9
|
+
const client = new Client({
|
|
10
|
+
ssl: {
|
|
11
|
+
rejectUnauthorized: false,
|
|
12
|
+
},
|
|
13
|
+
node: 'https://localhost:9200',
|
|
14
|
+
auth: {
|
|
15
|
+
username: 'admin',
|
|
16
|
+
password: 'admin',
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## The http Namespace
|
|
22
|
+
The `http` namespace comes with all functions representing HTTP methods like `connect`, `delete`, `get`, `head`, `options`, `patch`, `post`, `put`, and `trace`.
|
|
23
|
+
|
|
24
|
+
Let's create in index using `http.put`:
|
|
25
|
+
```javascript
|
|
26
|
+
await client.http.put({
|
|
27
|
+
path: '/movies',
|
|
28
|
+
body: {
|
|
29
|
+
mappings: {
|
|
30
|
+
properties: {
|
|
31
|
+
title: { type: 'text' },
|
|
32
|
+
director: { type: 'text' },
|
|
33
|
+
year: { type: 'integer' },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Make sure that the index was created successfully using `http.head`:
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
await client.http.head({ path: '/movies' });
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Add two documents to the index using `http.post` and the bulk endpoint
|
|
47
|
+
```javascript
|
|
48
|
+
const body = [
|
|
49
|
+
{ index: { _index: index } },
|
|
50
|
+
{ title: 'The quick brown fox' },
|
|
51
|
+
{ index: { _index: index } },
|
|
52
|
+
{ title: 'The quick brown fox jumps over the lazy dog' },
|
|
53
|
+
];
|
|
54
|
+
await client.http.post({ path: `_bulk`, body });
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Delete the index using `http.delete`:
|
|
58
|
+
```javascript
|
|
59
|
+
await client.http.delete({ path: '/movies' });
|
|
60
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Multi-Search (msearch)
|
|
2
|
+
|
|
3
|
+
OpenSearch's Multi-Search (`msearch`) API allows you to execute multiple search operations for documents within an index efficiently. This API supports various parameters that provide flexibility in customizing your search operations. It's crucial to understand the key differences between `msearch` and a regular `search` operation in OpenSearch. Unlike a single search operation, `msearch` enables you to perform multiple searches in a single API call, significantly reducing network overhead as it need not initialize a new network connection for each search. This proves particularly advantageous for batch operations or scenarios where searches span multiple indices. By combining searches into one request, `msearch` streamlines the process and enhances overall efficiency. However, it's important to note that there will also be a bit more memory overhead in the `msearch`, as the coordinating node will have to accumulate the various search responses in memory before sending back the final response. Explore the functionalities of the msearch API with the provided sample code in [../samples/msearch.js](../samples/msearch.js).
|
|
4
|
+
|
|
5
|
+
# Setup
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
const host = "localhost";
|
|
9
|
+
const protocol = "https";
|
|
10
|
+
const port = 9200;
|
|
11
|
+
const auth = "admin:admin";
|
|
12
|
+
const ca_certs_path = "/full/path/to/root-ca.pem";
|
|
13
|
+
const { Client } = require("@opensearch-project/opensearch");
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
const client = new Client({
|
|
16
|
+
node: `${protocol}://${auth}@${host}:${port}`,
|
|
17
|
+
ssl: {
|
|
18
|
+
ca: fs.readFileSync(ca_certs_path),
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
await client.bulk({
|
|
23
|
+
body: [
|
|
24
|
+
{ index: { _index: 'movies', _id: 1 } },
|
|
25
|
+
{ title: 'The Godfather', director: 'Francis Ford Coppola', year: 1972 },
|
|
26
|
+
{ index: { _index: 'movies', _id: 2 } },
|
|
27
|
+
{ title: 'The Godfather: Part II', director: 'Francis Ford Coppola', year: 1974 },
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
await client.index.refresh({ index: 'movies' });
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
# Multi Search API
|
|
35
|
+
|
|
36
|
+
The multi-search allows you to execute multiple search requests within a single API call. The following example shows how each search query provides a list of documents from the movie index.
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
try {
|
|
40
|
+
const queries = [
|
|
41
|
+
{},
|
|
42
|
+
{ query: { match: { title: 'The Godfather' } } },
|
|
43
|
+
{},
|
|
44
|
+
{ query: { match: { title: 'Part II' } } },
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const multiSearchResponse = await client.msearch({
|
|
48
|
+
index: 'movies',
|
|
49
|
+
body: queries,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
multiSearchResponse.body.responses.map((res) =>
|
|
53
|
+
res.hits.hits.map((movie) => {
|
|
54
|
+
console.log(movie._source);
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error('An error occurred:', error);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
# Cleanup
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
await client.indices.delete({index: 'movies'});
|
|
66
|
+
```
|
package/guides/search.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Search
|
|
2
|
-
OpenSearch provides a powerful search API that allows you to search for documents in an index. The search API supports a number of parameters that allow you to customize the search operation. In this guide, we will explore the search API and its parameters.
|
|
2
|
+
OpenSearch provides a powerful search API that allows you to search for documents in an index. The search API supports a number of parameters that allow you to customize the search operation. In this guide, we will explore the search API and its parameters. To complement your exploration of the OpenSearch Search API and its parameters, a working sample is available in [`../samples/search.js`](../samples/search.js).
|
|
3
3
|
# Setup
|
|
4
4
|
Let's start by creating an index and adding some documents to it:
|
|
5
5
|
```javascript
|
package/index.d.ts
CHANGED
|
@@ -138,6 +138,7 @@ interface ClientOptions {
|
|
|
138
138
|
};
|
|
139
139
|
disablePrototypePoisoningProtection?: boolean | 'proto' | 'constructor';
|
|
140
140
|
memoryCircuitBreaker?: MemoryCircuitBreakerOptions;
|
|
141
|
+
enableLongNumeralSupport?: boolean;
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
declare class Client {
|
|
@@ -2072,6 +2073,53 @@ declare class Client {
|
|
|
2072
2073
|
options: TransportRequestOptions,
|
|
2073
2074
|
callback: callbackFn<TResponse, TContext>
|
|
2074
2075
|
): TransportRequestCallback;
|
|
2076
|
+
http: {
|
|
2077
|
+
connect<TResponse = Record<string, any>, TContext = Context>(
|
|
2078
|
+
params: RequestParams.HttpParams,
|
|
2079
|
+
options?: TransportRequestOptions,
|
|
2080
|
+
callback?: callbackFn<TResponse, TContext>
|
|
2081
|
+
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2082
|
+
delete<TResponse = Record<string, any>, TContext = Context>(
|
|
2083
|
+
params: RequestParams.HttpParams,
|
|
2084
|
+
options?: TransportRequestOptions,
|
|
2085
|
+
callback?: callbackFn<TResponse, TContext>
|
|
2086
|
+
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2087
|
+
get<TResponse = Record<string, any>, TContext = Context>(
|
|
2088
|
+
params: RequestParams.HttpParams,
|
|
2089
|
+
options?: TransportRequestOptions,
|
|
2090
|
+
callback?: callbackFn<TResponse, TContext>
|
|
2091
|
+
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2092
|
+
head<TResponse = Record<string, any>, TContext = Context>(
|
|
2093
|
+
params: RequestParams.HttpParams,
|
|
2094
|
+
options?: TransportRequestOptions,
|
|
2095
|
+
callback?: callbackFn<TResponse, TContext>
|
|
2096
|
+
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2097
|
+
options<TResponse = Record<string, any>, TContext = Context>(
|
|
2098
|
+
params: RequestParams.HttpParams,
|
|
2099
|
+
options?: TransportRequestOptions,
|
|
2100
|
+
callback?: callbackFn<TResponse, TContext>
|
|
2101
|
+
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2102
|
+
patch<TResponse = Record<string, any>, TContext = Context>(
|
|
2103
|
+
params: RequestParams.HttpParams,
|
|
2104
|
+
options?: TransportRequestOptions,
|
|
2105
|
+
callback?: callbackFn<TResponse, TContext>
|
|
2106
|
+
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2107
|
+
post<TResponse = Record<string, any>, TContext = Context>(
|
|
2108
|
+
params: RequestParams.HttpParams,
|
|
2109
|
+
options?: TransportRequestOptions,
|
|
2110
|
+
callback?: callbackFn<TResponse, TContext>
|
|
2111
|
+
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2112
|
+
put<TResponse = Record<string, any>, TContext = Context>(
|
|
2113
|
+
params: RequestParams.HttpParams,
|
|
2114
|
+
options?: TransportRequestOptions,
|
|
2115
|
+
callback?: callbackFn<TResponse, TContext>
|
|
2116
|
+
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2117
|
+
trace<TResponse = Record<string, any>, TContext = Context>(
|
|
2118
|
+
params: RequestParams.HttpParams,
|
|
2119
|
+
options?: TransportRequestOptions,
|
|
2120
|
+
callback?: callbackFn<TResponse, TContext>
|
|
2121
|
+
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2122
|
+
};
|
|
2075
2123
|
index<
|
|
2076
2124
|
TResponse = Record<string, any>,
|
|
2077
2125
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -2359,33 +2407,41 @@ declare class Client {
|
|
|
2359
2407
|
options: TransportRequestOptions,
|
|
2360
2408
|
callback: callbackFn<TResponse, TContext>
|
|
2361
2409
|
): TransportRequestCallback;
|
|
2410
|
+
/** @deprecated use delete_index_template instead */
|
|
2362
2411
|
delete_template<TResponse = Record<string, any>, TContext = Context>(
|
|
2363
2412
|
params?: RequestParams.IndicesDeleteTemplate,
|
|
2364
2413
|
options?: TransportRequestOptions
|
|
2365
2414
|
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2415
|
+
/** @deprecated use delete_index_template instead */
|
|
2366
2416
|
delete_template<TResponse = Record<string, any>, TContext = Context>(
|
|
2367
2417
|
callback: callbackFn<TResponse, TContext>
|
|
2368
2418
|
): TransportRequestCallback;
|
|
2419
|
+
/** @deprecated use delete_index_template instead */
|
|
2369
2420
|
delete_template<TResponse = Record<string, any>, TContext = Context>(
|
|
2370
2421
|
params: RequestParams.IndicesDeleteTemplate,
|
|
2371
2422
|
callback: callbackFn<TResponse, TContext>
|
|
2372
2423
|
): TransportRequestCallback;
|
|
2424
|
+
/** @deprecated use delete_index_template instead */
|
|
2373
2425
|
delete_template<TResponse = Record<string, any>, TContext = Context>(
|
|
2374
2426
|
params: RequestParams.IndicesDeleteTemplate,
|
|
2375
2427
|
options: TransportRequestOptions,
|
|
2376
2428
|
callback: callbackFn<TResponse, TContext>
|
|
2377
2429
|
): TransportRequestCallback;
|
|
2430
|
+
/** @deprecated use deleteIndexTemplate instead */
|
|
2378
2431
|
deleteTemplate<TResponse = Record<string, any>, TContext = Context>(
|
|
2379
2432
|
params?: RequestParams.IndicesDeleteTemplate,
|
|
2380
2433
|
options?: TransportRequestOptions
|
|
2381
2434
|
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2435
|
+
/** @deprecated use deleteIndexTemplate instead */
|
|
2382
2436
|
deleteTemplate<TResponse = Record<string, any>, TContext = Context>(
|
|
2383
2437
|
callback: callbackFn<TResponse, TContext>
|
|
2384
2438
|
): TransportRequestCallback;
|
|
2439
|
+
/** @deprecated use deleteIndexTemplate instead */
|
|
2385
2440
|
deleteTemplate<TResponse = Record<string, any>, TContext = Context>(
|
|
2386
2441
|
params: RequestParams.IndicesDeleteTemplate,
|
|
2387
2442
|
callback: callbackFn<TResponse, TContext>
|
|
2388
2443
|
): TransportRequestCallback;
|
|
2444
|
+
/** @deprecated use deleteIndexTemplate instead */
|
|
2389
2445
|
deleteTemplate<TResponse = Record<string, any>, TContext = Context>(
|
|
2390
2446
|
params: RequestParams.IndicesDeleteTemplate,
|
|
2391
2447
|
options: TransportRequestOptions,
|
|
@@ -2503,33 +2559,41 @@ declare class Client {
|
|
|
2503
2559
|
options: TransportRequestOptions,
|
|
2504
2560
|
callback: callbackFn<TResponse, TContext>
|
|
2505
2561
|
): TransportRequestCallback;
|
|
2562
|
+
/** @deprecated use exists_index_template instead */
|
|
2506
2563
|
exists_template<TResponse = boolean, TContext = Context>(
|
|
2507
2564
|
params?: RequestParams.IndicesExistsTemplate,
|
|
2508
2565
|
options?: TransportRequestOptions
|
|
2509
2566
|
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2567
|
+
/** @deprecated use exists_index_template instead */
|
|
2510
2568
|
exists_template<TResponse = boolean, TContext = Context>(
|
|
2511
2569
|
callback: callbackFn<TResponse, TContext>
|
|
2512
2570
|
): TransportRequestCallback;
|
|
2571
|
+
/** @deprecated use exists_index_template instead */
|
|
2513
2572
|
exists_template<TResponse = boolean, TContext = Context>(
|
|
2514
2573
|
params: RequestParams.IndicesExistsTemplate,
|
|
2515
2574
|
callback: callbackFn<TResponse, TContext>
|
|
2516
2575
|
): TransportRequestCallback;
|
|
2576
|
+
/** @deprecated use exists_index_template instead */
|
|
2517
2577
|
exists_template<TResponse = boolean, TContext = Context>(
|
|
2518
2578
|
params: RequestParams.IndicesExistsTemplate,
|
|
2519
2579
|
options: TransportRequestOptions,
|
|
2520
2580
|
callback: callbackFn<TResponse, TContext>
|
|
2521
2581
|
): TransportRequestCallback;
|
|
2582
|
+
/** @deprecated use existsIndexTemplate instead */
|
|
2522
2583
|
existsTemplate<TResponse = boolean, TContext = Context>(
|
|
2523
2584
|
params?: RequestParams.IndicesExistsTemplate,
|
|
2524
2585
|
options?: TransportRequestOptions
|
|
2525
2586
|
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2587
|
+
/** @deprecated use existsIndexTemplate instead */
|
|
2526
2588
|
existsTemplate<TResponse = boolean, TContext = Context>(
|
|
2527
2589
|
callback: callbackFn<TResponse, TContext>
|
|
2528
2590
|
): TransportRequestCallback;
|
|
2591
|
+
/** @deprecated use existsIndexTemplate instead */
|
|
2529
2592
|
existsTemplate<TResponse = boolean, TContext = Context>(
|
|
2530
2593
|
params: RequestParams.IndicesExistsTemplate,
|
|
2531
2594
|
callback: callbackFn<TResponse, TContext>
|
|
2532
2595
|
): TransportRequestCallback;
|
|
2596
|
+
/** @deprecated use existsIndexTemplate instead */
|
|
2533
2597
|
existsTemplate<TResponse = boolean, TContext = Context>(
|
|
2534
2598
|
params: RequestParams.IndicesExistsTemplate,
|
|
2535
2599
|
options: TransportRequestOptions,
|
|
@@ -2775,33 +2839,41 @@ declare class Client {
|
|
|
2775
2839
|
options: TransportRequestOptions,
|
|
2776
2840
|
callback: callbackFn<TResponse, TContext>
|
|
2777
2841
|
): TransportRequestCallback;
|
|
2842
|
+
/** @deprecated use get_index_template instead */
|
|
2778
2843
|
get_template<TResponse = Record<string, any>, TContext = Context>(
|
|
2779
2844
|
params?: RequestParams.IndicesGetTemplate,
|
|
2780
2845
|
options?: TransportRequestOptions
|
|
2781
2846
|
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2847
|
+
/** @deprecated use get_index_template instead */
|
|
2782
2848
|
get_template<TResponse = Record<string, any>, TContext = Context>(
|
|
2783
2849
|
callback: callbackFn<TResponse, TContext>
|
|
2784
2850
|
): TransportRequestCallback;
|
|
2851
|
+
/** @deprecated use get_index_template instead */
|
|
2785
2852
|
get_template<TResponse = Record<string, any>, TContext = Context>(
|
|
2786
2853
|
params: RequestParams.IndicesGetTemplate,
|
|
2787
2854
|
callback: callbackFn<TResponse, TContext>
|
|
2788
2855
|
): TransportRequestCallback;
|
|
2856
|
+
/** @deprecated use get_index_template instead */
|
|
2789
2857
|
get_template<TResponse = Record<string, any>, TContext = Context>(
|
|
2790
2858
|
params: RequestParams.IndicesGetTemplate,
|
|
2791
2859
|
options: TransportRequestOptions,
|
|
2792
2860
|
callback: callbackFn<TResponse, TContext>
|
|
2793
2861
|
): TransportRequestCallback;
|
|
2862
|
+
/** @deprecated use getIndexTemplate instead */
|
|
2794
2863
|
getTemplate<TResponse = Record<string, any>, TContext = Context>(
|
|
2795
2864
|
params?: RequestParams.IndicesGetTemplate,
|
|
2796
2865
|
options?: TransportRequestOptions
|
|
2797
2866
|
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
2867
|
+
/** @deprecated use getIndexTemplate instead */
|
|
2798
2868
|
getTemplate<TResponse = Record<string, any>, TContext = Context>(
|
|
2799
2869
|
callback: callbackFn<TResponse, TContext>
|
|
2800
2870
|
): TransportRequestCallback;
|
|
2871
|
+
/** @deprecated use getIndexTemplate instead */
|
|
2801
2872
|
getTemplate<TResponse = Record<string, any>, TContext = Context>(
|
|
2802
2873
|
params: RequestParams.IndicesGetTemplate,
|
|
2803
2874
|
callback: callbackFn<TResponse, TContext>
|
|
2804
2875
|
): TransportRequestCallback;
|
|
2876
|
+
/** @deprecated use getIndexTemplate instead */
|
|
2805
2877
|
getTemplate<TResponse = Record<string, any>, TContext = Context>(
|
|
2806
2878
|
params: RequestParams.IndicesGetTemplate,
|
|
2807
2879
|
options: TransportRequestOptions,
|
|
@@ -3111,6 +3183,7 @@ declare class Client {
|
|
|
3111
3183
|
options: TransportRequestOptions,
|
|
3112
3184
|
callback: callbackFn<TResponse, TContext>
|
|
3113
3185
|
): TransportRequestCallback;
|
|
3186
|
+
/** @deprecated use put_index_template instead */
|
|
3114
3187
|
put_template<
|
|
3115
3188
|
TResponse = Record<string, any>,
|
|
3116
3189
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3119,6 +3192,7 @@ declare class Client {
|
|
|
3119
3192
|
params?: RequestParams.IndicesPutTemplate<TRequestBody>,
|
|
3120
3193
|
options?: TransportRequestOptions
|
|
3121
3194
|
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
3195
|
+
/** @deprecated use put_index_template instead */
|
|
3122
3196
|
put_template<
|
|
3123
3197
|
TResponse = Record<string, any>,
|
|
3124
3198
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3126,6 +3200,7 @@ declare class Client {
|
|
|
3126
3200
|
>(
|
|
3127
3201
|
callback: callbackFn<TResponse, TContext>
|
|
3128
3202
|
): TransportRequestCallback;
|
|
3203
|
+
/** @deprecated use put_index_template instead */
|
|
3129
3204
|
put_template<
|
|
3130
3205
|
TResponse = Record<string, any>,
|
|
3131
3206
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3134,6 +3209,7 @@ declare class Client {
|
|
|
3134
3209
|
params: RequestParams.IndicesPutTemplate<TRequestBody>,
|
|
3135
3210
|
callback: callbackFn<TResponse, TContext>
|
|
3136
3211
|
): TransportRequestCallback;
|
|
3212
|
+
/** @deprecated use put_index_template instead */
|
|
3137
3213
|
put_template<
|
|
3138
3214
|
TResponse = Record<string, any>,
|
|
3139
3215
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3143,6 +3219,7 @@ declare class Client {
|
|
|
3143
3219
|
options: TransportRequestOptions,
|
|
3144
3220
|
callback: callbackFn<TResponse, TContext>
|
|
3145
3221
|
): TransportRequestCallback;
|
|
3222
|
+
/** @deprecated use putIndexTemplate instead */
|
|
3146
3223
|
putTemplate<
|
|
3147
3224
|
TResponse = Record<string, any>,
|
|
3148
3225
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3151,6 +3228,7 @@ declare class Client {
|
|
|
3151
3228
|
params?: RequestParams.IndicesPutTemplate<TRequestBody>,
|
|
3152
3229
|
options?: TransportRequestOptions
|
|
3153
3230
|
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
3231
|
+
/** @deprecated use putIndexTemplate instead */
|
|
3154
3232
|
putTemplate<
|
|
3155
3233
|
TResponse = Record<string, any>,
|
|
3156
3234
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3158,6 +3236,7 @@ declare class Client {
|
|
|
3158
3236
|
>(
|
|
3159
3237
|
callback: callbackFn<TResponse, TContext>
|
|
3160
3238
|
): TransportRequestCallback;
|
|
3239
|
+
/** @deprecated use putIndexTemplate instead */
|
|
3161
3240
|
putTemplate<
|
|
3162
3241
|
TResponse = Record<string, any>,
|
|
3163
3242
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3166,6 +3245,7 @@ declare class Client {
|
|
|
3166
3245
|
params: RequestParams.IndicesPutTemplate<TRequestBody>,
|
|
3167
3246
|
callback: callbackFn<TResponse, TContext>
|
|
3168
3247
|
): TransportRequestCallback;
|
|
3248
|
+
/** @deprecated use putIndexTemplate instead */
|
|
3169
3249
|
putTemplate<
|
|
3170
3250
|
TResponse = Record<string, any>,
|
|
3171
3251
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3415,6 +3495,7 @@ declare class Client {
|
|
|
3415
3495
|
options: TransportRequestOptions,
|
|
3416
3496
|
callback: callbackFn<TResponse, TContext>
|
|
3417
3497
|
): TransportRequestCallback;
|
|
3498
|
+
/** @deprecated use simulate_index_template instead */
|
|
3418
3499
|
simulate_template<
|
|
3419
3500
|
TResponse = Record<string, any>,
|
|
3420
3501
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3423,6 +3504,7 @@ declare class Client {
|
|
|
3423
3504
|
params?: RequestParams.IndicesSimulateTemplate<TRequestBody>,
|
|
3424
3505
|
options?: TransportRequestOptions
|
|
3425
3506
|
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
3507
|
+
/** @deprecated use simulate_index_template instead */
|
|
3426
3508
|
simulate_template<
|
|
3427
3509
|
TResponse = Record<string, any>,
|
|
3428
3510
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3430,6 +3512,7 @@ declare class Client {
|
|
|
3430
3512
|
>(
|
|
3431
3513
|
callback: callbackFn<TResponse, TContext>
|
|
3432
3514
|
): TransportRequestCallback;
|
|
3515
|
+
/** @deprecated use simulate_index_template instead */
|
|
3433
3516
|
simulate_template<
|
|
3434
3517
|
TResponse = Record<string, any>,
|
|
3435
3518
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3438,6 +3521,7 @@ declare class Client {
|
|
|
3438
3521
|
params: RequestParams.IndicesSimulateTemplate<TRequestBody>,
|
|
3439
3522
|
callback: callbackFn<TResponse, TContext>
|
|
3440
3523
|
): TransportRequestCallback;
|
|
3524
|
+
/** @deprecated use simulate_index_template instead */
|
|
3441
3525
|
simulate_template<
|
|
3442
3526
|
TResponse = Record<string, any>,
|
|
3443
3527
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3447,6 +3531,7 @@ declare class Client {
|
|
|
3447
3531
|
options: TransportRequestOptions,
|
|
3448
3532
|
callback: callbackFn<TResponse, TContext>
|
|
3449
3533
|
): TransportRequestCallback;
|
|
3534
|
+
/** @deprecated use simulateIndexTemplate instead */
|
|
3450
3535
|
simulateTemplate<
|
|
3451
3536
|
TResponse = Record<string, any>,
|
|
3452
3537
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3455,6 +3540,7 @@ declare class Client {
|
|
|
3455
3540
|
params?: RequestParams.IndicesSimulateTemplate<TRequestBody>,
|
|
3456
3541
|
options?: TransportRequestOptions
|
|
3457
3542
|
): TransportRequestPromise<ApiResponse<TResponse, TContext>>;
|
|
3543
|
+
/** @deprecated use simulateIndexTemplate instead */
|
|
3458
3544
|
simulateTemplate<
|
|
3459
3545
|
TResponse = Record<string, any>,
|
|
3460
3546
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3462,6 +3548,7 @@ declare class Client {
|
|
|
3462
3548
|
>(
|
|
3463
3549
|
callback: callbackFn<TResponse, TContext>
|
|
3464
3550
|
): TransportRequestCallback;
|
|
3551
|
+
/** @deprecated use simulateIndexTemplate instead */
|
|
3465
3552
|
simulateTemplate<
|
|
3466
3553
|
TResponse = Record<string, any>,
|
|
3467
3554
|
TRequestBody extends RequestBody = Record<string, any>,
|
|
@@ -3470,6 +3557,7 @@ declare class Client {
|
|
|
3470
3557
|
params: RequestParams.IndicesSimulateTemplate<TRequestBody>,
|
|
3471
3558
|
callback: callbackFn<TResponse, TContext>
|
|
3472
3559
|
): TransportRequestCallback;
|
|
3560
|
+
/** @deprecated use simulateIndexTemplate instead */
|
|
3473
3561
|
simulateTemplate<
|
|
3474
3562
|
TResponse = Record<string, any>,
|
|
3475
3563
|
TRequestBody extends RequestBody = Record<string, any>,
|
package/lib/Transport.js
CHANGED
|
@@ -197,8 +197,8 @@ class Transport {
|
|
|
197
197
|
isStream(params.body) || isStream(params.bulkBody)
|
|
198
198
|
? 0
|
|
199
199
|
: typeof options.maxRetries === 'number'
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
? options.maxRetries
|
|
201
|
+
: this.maxRetries;
|
|
202
202
|
const compression = options.compression !== undefined ? options.compression : this.compression;
|
|
203
203
|
let request = { abort: noop };
|
|
204
204
|
const transportReturn = {
|
|
@@ -729,4 +729,5 @@ module.exports.internals = {
|
|
|
729
729
|
randomSelector,
|
|
730
730
|
generateRequestId,
|
|
731
731
|
lowerCaseHeaders,
|
|
732
|
+
toMs,
|
|
732
733
|
};
|
|
@@ -14,6 +14,7 @@ const Transport = require('../Transport');
|
|
|
14
14
|
const aws4 = require('aws4');
|
|
15
15
|
const AwsSigv4SignerError = require('./errors');
|
|
16
16
|
const crypto = require('crypto');
|
|
17
|
+
const { toMs } = Transport.internals;
|
|
17
18
|
|
|
18
19
|
const getAwsSDKCredentialsProvider = async () => {
|
|
19
20
|
// First try V3
|
|
@@ -102,6 +103,12 @@ function AwsSigv4Signer(opts = {}) {
|
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
const currentCredentials = credentialsState.credentials;
|
|
106
|
+
/**
|
|
107
|
+
* For AWS SDK V3
|
|
108
|
+
* Make sure token will expire no earlier than `expiryBufferMs` milliseconds in the future.
|
|
109
|
+
*/
|
|
110
|
+
const expiryBufferMs = toMs(options.requestTimeout || this.requestTimeout);
|
|
111
|
+
|
|
105
112
|
let expired = false;
|
|
106
113
|
if (!currentCredentials) {
|
|
107
114
|
// Credentials haven't been acquired yet.
|
|
@@ -120,7 +127,10 @@ function AwsSigv4Signer(opts = {}) {
|
|
|
120
127
|
expired = true;
|
|
121
128
|
}
|
|
122
129
|
// AWS SDK V3, Credentials.expiration is a Date object
|
|
123
|
-
else if (
|
|
130
|
+
else if (
|
|
131
|
+
currentCredentials.expiration &&
|
|
132
|
+
currentCredentials.expiration.getTime() - Date.now() < expiryBufferMs
|
|
133
|
+
) {
|
|
124
134
|
expired = true;
|
|
125
135
|
}
|
|
126
136
|
|
package/package.json
CHANGED
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
"types": "./index.d.ts",
|
|
10
10
|
"import": "./index.mjs"
|
|
11
11
|
},
|
|
12
|
+
"./api/new": {
|
|
13
|
+
"types": "./api/new.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./api/types": {
|
|
16
|
+
"types": "./api/types.d.ts"
|
|
17
|
+
},
|
|
12
18
|
"./aws": "./lib/aws/index.js",
|
|
13
19
|
"./*": "./*"
|
|
14
20
|
},
|
|
@@ -23,7 +29,7 @@
|
|
|
23
29
|
}
|
|
24
30
|
},
|
|
25
31
|
"homepage": "https://www.opensearch.org/",
|
|
26
|
-
"version": "2.
|
|
32
|
+
"version": "2.5.0",
|
|
27
33
|
"versionCanary": "7.10.0-canary.6",
|
|
28
34
|
"keywords": [
|
|
29
35
|
"opensearch",
|
|
@@ -59,15 +65,15 @@
|
|
|
59
65
|
"@aws-sdk/types": "^3.160.0",
|
|
60
66
|
"@babel/eslint-parser": "^7.19.1",
|
|
61
67
|
"@sinonjs/fake-timers": "github:sinonjs/fake-timers#0bfffc1",
|
|
62
|
-
"@types/node": "^
|
|
68
|
+
"@types/node": "^20.1.4",
|
|
63
69
|
"convert-hrtime": "^5.0.0",
|
|
64
70
|
"cross-zip": "^4.0.0",
|
|
65
|
-
"dedent": "^
|
|
71
|
+
"dedent": "^1.1.0",
|
|
66
72
|
"deepmerge": "^4.2.2",
|
|
67
73
|
"dezalgo": "^1.0.3",
|
|
68
74
|
"eslint": "^8.30.0",
|
|
69
|
-
"eslint-config-prettier": "^
|
|
70
|
-
"eslint-plugin-prettier": "^
|
|
75
|
+
"eslint-config-prettier": "^9.0.0",
|
|
76
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
71
77
|
"fast-deep-equal": "^3.1.3",
|
|
72
78
|
"into-stream": "^6.0.0",
|
|
73
79
|
"js-yaml": "^4.1.0",
|
|
@@ -75,8 +81,8 @@
|
|
|
75
81
|
"license-checker": "^25.0.1",
|
|
76
82
|
"minimist": "^1.2.5",
|
|
77
83
|
"node-fetch": "^3.2.10",
|
|
78
|
-
"ora": "^
|
|
79
|
-
"prettier": "^
|
|
84
|
+
"ora": "^8.0.1",
|
|
85
|
+
"prettier": "^3.0.1",
|
|
80
86
|
"pretty-hrtime": "^1.0.3",
|
|
81
87
|
"proxy": "^1.0.2",
|
|
82
88
|
"rimraf": "^5.0.0",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# OpenSearch JavaScript Samples
|
|
2
|
+
|
|
3
|
+
Most samples can be run using OpenSearch installed locally with docker.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
docker pull opensearchproject/opensearch:latest
|
|
7
|
+
docker run -d -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" opensearchproject/opensearch:latest
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Run Samples
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
node json.js
|
|
14
|
+
```
|