@sebspark/opensearch 2.0.0 → 2.0.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/dist/index.js +5 -35
- package/dist/index.js.map +1 -0
- package/package.json +3 -3
- package/dist/index.d.mts +0 -503
- package/dist/index.mjs +0 -45
package/dist/index.js
CHANGED
|
@@ -1,37 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
OpenSearchClient: () => OpenSearchClient,
|
|
24
|
-
bulkCreate: () => bulkCreate,
|
|
25
|
-
bulkDelete: () => bulkDelete,
|
|
26
|
-
bulkIndex: () => bulkIndex,
|
|
27
|
-
bulkUpdate: () => bulkUpdate
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(index_exports);
|
|
30
|
-
|
|
31
1
|
// src/client.ts
|
|
32
|
-
|
|
2
|
+
import { Client } from "@opensearch-project/opensearch";
|
|
33
3
|
var OpenSearchClient = function(...args) {
|
|
34
|
-
const clientInstance = new
|
|
4
|
+
const clientInstance = new Client(...args);
|
|
35
5
|
return clientInstance;
|
|
36
6
|
};
|
|
37
7
|
|
|
@@ -66,11 +36,11 @@ function bulkDelete(index, ids) {
|
|
|
66
36
|
});
|
|
67
37
|
return { index, body };
|
|
68
38
|
}
|
|
69
|
-
|
|
70
|
-
0 && (module.exports = {
|
|
39
|
+
export {
|
|
71
40
|
OpenSearchClient,
|
|
72
41
|
bulkCreate,
|
|
73
42
|
bulkDelete,
|
|
74
43
|
bulkIndex,
|
|
75
44
|
bulkUpdate
|
|
76
|
-
}
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/helpers.ts"],"sourcesContent":["import { type API, Client } from '@opensearch-project/opensearch'\nimport type {\n BulkRequest,\n BulkResponse,\n IndexDefinition,\n IndexRequest,\n SearchRequest,\n SearchResponse,\n} from './types'\nimport type {\n Indices,\n TransportRequestOptions,\n TransportRequestPromise,\n} from './types/common'\nimport type { IndicesExistsRequest } from './types/indx'\n\ntype TypedIndices = Omit<Indices, 'exists'> & {\n exists<T extends IndexDefinition>(\n params: IndicesExistsRequest<T>,\n options?: TransportRequestOptions\n ): TransportRequestPromise<API.Indices_Exists_Response>\n}\n\n/**\n * ✅ Custom interface that extends `Client`, but replaces the `search()` method signature.\n * - Uses `Omit<Client, \"search\">` to remove `search()` from `Client`.\n * - Defines a new `search<T>()` method with stricter type safety.\n */\nexport interface OpenSearchClient\n extends Omit<Client, 'search' | 'index' | 'bulk' | 'indices'> {\n search<T extends IndexDefinition>(\n params: SearchRequest<T>,\n options?: TransportRequestOptions\n ): TransportRequestPromise<SearchResponse<T>>\n\n index<T extends IndexDefinition>(\n params: IndexRequest<T>,\n options?: TransportRequestOptions\n ): TransportRequestPromise<API.Index_Response>\n\n bulk<T extends IndexDefinition>(\n params: BulkRequest<T>,\n options?: TransportRequestOptions\n ): TransportRequestPromise<BulkResponse<T>>\n\n indices: TypedIndices\n}\n\n/**\n * ✅ Constructor type that ensures `new OpenSearchClient()` works.\n * - This type is necessary because `OpenSearchClient` is actually a function (not a class).\n */\ntype OpenSearchClientConstructor = new (\n ...args: ConstructorParameters<typeof Client>\n) => OpenSearchClient\n\n/**\n * ✅ A function that behaves like a class constructor.\n * - Instantiates a new `Client` internally.\n * - Casts the instance to `OpenSearchClient` so TypeScript recognizes the new `search<T>()` signature.\n * - The `as unknown as` trick ensures `new OpenSearchClient()` is valid.\n */\nexport const OpenSearchClient: OpenSearchClientConstructor = function (\n this: Client,\n ...args: ConstructorParameters<typeof Client>\n) {\n const clientInstance = new Client(...args)\n return clientInstance as unknown as OpenSearchClient\n} as unknown as {\n new (...args: ConstructorParameters<typeof Client>): OpenSearchClient\n}\n","import type { Types } from '@opensearch-project/opensearch'\nimport type {\n BulkRequest,\n CreateOperation,\n DeleteOperation,\n IndexOperation,\n UpdateAction,\n UpdateOperation,\n} from './types/bulk'\nimport type { IndexDefinition } from './types/common'\nimport type { DocumentFor } from './types/documents'\n\nexport type IdFunction<T extends IndexDefinition> = (\n doc: DocumentFor<T>\n) => Types.Common.Id\n\n/**\n * Constructs a bulk request payload for indexing documents.\n *\n * For each document in the provided array, this helper creates a two‑line bulk operation:\n * 1. An action object for an index operation. If an id generator is provided, its result is used as _id.\n * 2. The document itself.\n *\n * @param index - The name of the index.\n * @param docs - An array of documents to insert.\n * @param idFn - Optional function that returns an _id for a given document.\n * @returns A BulkRequest payload for insert operations.\n */\nexport function bulkIndex<T extends IndexDefinition>(\n index: T['index'],\n docs: DocumentFor<T>[],\n idFn?: IdFunction<T>\n): BulkRequest<T> {\n const body = docs.flatMap((doc) => {\n const op: IndexOperation<T> = idFn ? { _id: idFn(doc) } : {}\n return [{ index: op }, doc]\n })\n return { index, body }\n}\n\n/**\n * Constructs a bulk request payload for creating documents.\n *\n * For each document in the provided array, this helper creates a two‑line bulk operation:\n * 1. An action object for a create operation with a generated _id.\n * 2. The document itself.\n *\n * @param index - The name of the index.\n * @param docs - An array of documents to create.\n * @param idFn - A function that returns a unique _id for each document.\n * @returns A BulkRequest payload for create operations.\n */\nexport function bulkCreate<T extends IndexDefinition>(\n index: T['index'],\n docs: DocumentFor<T>[],\n idFn: IdFunction<T>\n): BulkRequest<T> {\n const body = docs.flatMap((doc) => {\n const op: CreateOperation<T> = { _id: idFn(doc) }\n return [{ create: op }, doc]\n })\n return { index, body }\n}\n\n/**\n * Constructs a bulk request payload for update operations.\n *\n * This helper takes an array of update actions (of type UpdateAction<T>),\n * splits each into its action metadata and payload (with the `doc` and/or `upsert` properties),\n * and returns a BulkRequest payload formatted as a flat array.\n *\n * @param index - The name of the index.\n * @param updates - An array of update actions.\n * @param idFn - A function that returns a unique _id for each document.\n * @returns A BulkRequest payload for update operations.\n */\nexport function bulkUpdate<T extends IndexDefinition>(\n index: T['index'],\n updates: UpdateAction<T>[],\n idFn: IdFunction<T>\n): BulkRequest<T> {\n const body = updates.flatMap((update) => {\n const op: UpdateOperation<T> = {\n _id: idFn((update.doc as DocumentFor<T>) || update.upsert),\n }\n return [{ update: op }, update]\n })\n\n return { index, body }\n}\n\n/**\n * Constructs a bulk request payload for deleting documents.\n *\n * For each document in the provided array, this helper creates a single‑line bulk operation:\n * { delete: { _id: <id> } }\n * The provided id generator function is used to compute the _id for each document.\n *\n * @param index - The name of the index.\n * @param docs - An array of documents to delete.\n * @param idFn - A function that returns the _id for a given document.\n * @returns A BulkRequest payload for delete operations.\n */\nexport function bulkDelete<T extends IndexDefinition>(\n index: T['index'],\n ids: Types.Common.Id[]\n): BulkRequest<T> {\n const body = ids.map((_id) => {\n const op: DeleteOperation<T> = { _id }\n return { delete: op }\n })\n return { index, body }\n}\n"],"mappings":";AAAA,SAAmB,cAAc;AA8D1B,IAAM,mBAAgD,YAExD,MACH;AACA,QAAM,iBAAiB,IAAI,OAAO,GAAG,IAAI;AACzC,SAAO;AACT;;;ACxCO,SAAS,UACd,OACA,MACA,MACgB;AAChB,QAAM,OAAO,KAAK,QAAQ,CAAC,QAAQ;AACjC,UAAM,KAAwB,OAAO,EAAE,KAAK,KAAK,GAAG,EAAE,IAAI,CAAC;AAC3D,WAAO,CAAC,EAAE,OAAO,GAAG,GAAG,GAAG;AAAA,EAC5B,CAAC;AACD,SAAO,EAAE,OAAO,KAAK;AACvB;AAcO,SAAS,WACd,OACA,MACA,MACgB;AAChB,QAAM,OAAO,KAAK,QAAQ,CAAC,QAAQ;AACjC,UAAM,KAAyB,EAAE,KAAK,KAAK,GAAG,EAAE;AAChD,WAAO,CAAC,EAAE,QAAQ,GAAG,GAAG,GAAG;AAAA,EAC7B,CAAC;AACD,SAAO,EAAE,OAAO,KAAK;AACvB;AAcO,SAAS,WACd,OACA,SACA,MACgB;AAChB,QAAM,OAAO,QAAQ,QAAQ,CAAC,WAAW;AACvC,UAAM,KAAyB;AAAA,MAC7B,KAAK,KAAM,OAAO,OAA0B,OAAO,MAAM;AAAA,IAC3D;AACA,WAAO,CAAC,EAAE,QAAQ,GAAG,GAAG,MAAM;AAAA,EAChC,CAAC;AAED,SAAO,EAAE,OAAO,KAAK;AACvB;AAcO,SAAS,WACd,OACA,KACgB;AAChB,QAAM,OAAO,IAAI,IAAI,CAAC,QAAQ;AAC5B,UAAM,KAAyB,EAAE,IAAI;AACrC,WAAO,EAAE,QAAQ,GAAG;AAAA,EACtB,CAAC;AACD,SAAO,EAAE,OAAO,KAAK;AACvB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/opensearch",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "tsup
|
|
12
|
+
"build": "tsup src/index.ts --config ./tsup.config.ts",
|
|
13
13
|
"dev": "tsc --watch --noEmit",
|
|
14
14
|
"lint": "biome check .",
|
|
15
15
|
"test": "vitest run --passWithNoTests --coverage",
|
package/dist/index.d.mts
DELETED
|
@@ -1,503 +0,0 @@
|
|
|
1
|
-
import { API, Types, Client } from '@opensearch-project/opensearch';
|
|
2
|
-
|
|
3
|
-
type DeepPartial<T> = {
|
|
4
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
5
|
-
};
|
|
6
|
-
type NestedPaths<T, Prefix extends string = ''> = T extends object ? {
|
|
7
|
-
[K in keyof T & string]: `${Prefix}${Prefix extends '' ? '' : '.'}${K}` | NestedPaths<T[K], `${Prefix}${Prefix extends '' ? '' : '.'}${K}`>;
|
|
8
|
-
}[keyof T & string] : never;
|
|
9
|
-
type NestedLeafPaths<T, Prefix extends string = ''> = T extends object ? {
|
|
10
|
-
[K in keyof T & string]: NestedLeafPaths<T[K], `${Prefix}${Prefix extends '' ? '' : '.'}${K}`>;
|
|
11
|
-
}[keyof T & string] : Prefix;
|
|
12
|
-
type Primitive = string | number | boolean;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Defines all possible field value types in OpenSearch.
|
|
16
|
-
*/
|
|
17
|
-
type FieldValue = Types.Common.FieldValue;
|
|
18
|
-
/**
|
|
19
|
-
* Defines an OpenSearch field with optional properties.
|
|
20
|
-
*/
|
|
21
|
-
type Property = Types.Common_Mapping.Property;
|
|
22
|
-
/**
|
|
23
|
-
* Defines an OpenSearch index mapping.
|
|
24
|
-
*/
|
|
25
|
-
type TypeMapping = Omit<Types.Common_Mapping.TypeMapping, 'properties'> & {
|
|
26
|
-
properties: Record<string, Property>;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Defines an OpenSearch index mapping configuration.
|
|
30
|
-
*/
|
|
31
|
-
type IndicesCreateRequestBody = Omit<API.Indices_Create_RequestBody, 'mappings'> & {
|
|
32
|
-
mappings: TypeMapping;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Defines an OpenSearch index with body required.
|
|
36
|
-
*/
|
|
37
|
-
type IndexDefinition = Omit<API.Indices_Create_Request, 'body'> & {
|
|
38
|
-
body: IndicesCreateRequestBody;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Converts OpenSearch field definitions into TypeScript types.
|
|
42
|
-
*/
|
|
43
|
-
type MapOpenSearchTypes<T> = T extends Property ? T['type'] extends 'keyword' | 'text' ? string : T['type'] extends 'integer' | 'long' | 'short' | 'byte' | 'float' | 'double' ? number : T['type'] extends 'boolean' ? boolean : T['type'] extends 'date' | 'date_nanos' ? Date : T['type'] extends 'object' | 'nested' ? T extends {
|
|
44
|
-
properties: Record<string, Property>;
|
|
45
|
-
} ? {
|
|
46
|
-
[K in keyof T['properties']]: MapOpenSearchTypes<T['properties'][K]>;
|
|
47
|
-
} : never : never : T extends Record<string, Property> ? {
|
|
48
|
-
[K in keyof T]: MapOpenSearchTypes<T[K]>;
|
|
49
|
-
} : never;
|
|
50
|
-
type MapQueryProperties<T extends IndexDefinition> = T extends {
|
|
51
|
-
body: {
|
|
52
|
-
mappings: {
|
|
53
|
-
properties: infer P;
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
} ? MapOpenSearchTypes<P> : never;
|
|
57
|
-
type Indices = Client['indices'];
|
|
58
|
-
type TransportRequestOptions = Parameters<Indices['exists']>[1];
|
|
59
|
-
interface TransportRequestPromise<T> extends Promise<T> {
|
|
60
|
-
abort: () => void;
|
|
61
|
-
finally(onFinally?: (() => void) | undefined | null): Promise<T>;
|
|
62
|
-
}
|
|
63
|
-
type Sort<T> = SortOptions<T> | SortOptions<T>[];
|
|
64
|
-
type SortOptions<T> = '_score' | '_doc' | {
|
|
65
|
-
_doc?: Types.Common.ScoreSort;
|
|
66
|
-
_geo_distance?: Types.Common.GeoDistanceSort;
|
|
67
|
-
_score?: Types.Common.ScoreSort;
|
|
68
|
-
_script?: Types.Common.ScriptSort;
|
|
69
|
-
} | Record<NestedPaths<T>, Types.Common.FieldSort>;
|
|
70
|
-
type BuiltinKeys = '_id' | '_index';
|
|
71
|
-
|
|
72
|
-
type DocumentFor<T extends IndexDefinition> = {
|
|
73
|
-
[P in keyof T['body']['mappings']['properties']]: MapOpenSearchTypes<T['body']['mappings']['properties'][P]>;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
type CreateOperation<T extends IndexDefinition> = Omit<WriteOperation<T>, '_id'> & {
|
|
77
|
-
_id: Types.Common.Id;
|
|
78
|
-
};
|
|
79
|
-
type DeleteOperation<T extends IndexDefinition> = OperationBase<T>;
|
|
80
|
-
type IndexOperation<T extends IndexDefinition> = WriteOperation<T>;
|
|
81
|
-
type UpdateOperation<T extends IndexDefinition> = Omit<Types.Core_Bulk.UpdateOperation, '_index' | '_id'> & {
|
|
82
|
-
_id: Types.Common.Id;
|
|
83
|
-
_index?: T['index'];
|
|
84
|
-
};
|
|
85
|
-
type WriteOperation<T extends IndexDefinition> = Omit<Types.Core_Bulk.WriteOperation, '_index'> & {
|
|
86
|
-
_index?: T['index'];
|
|
87
|
-
};
|
|
88
|
-
type OperationBase<T extends IndexDefinition> = Omit<Types.Core_Bulk.OperationBase, '_index'> & {
|
|
89
|
-
_index?: T['index'];
|
|
90
|
-
};
|
|
91
|
-
type OperationContainer<T extends IndexDefinition> = {
|
|
92
|
-
create?: CreateOperation<T>;
|
|
93
|
-
delete?: DeleteOperation<T>;
|
|
94
|
-
index?: IndexOperation<T>;
|
|
95
|
-
update?: UpdateOperation<T>;
|
|
96
|
-
};
|
|
97
|
-
type UpdateAction<T extends IndexDefinition> = Omit<Types.Core_Bulk.UpdateAction, 'doc' | 'upsert'> & ({
|
|
98
|
-
doc: DeepPartial<DocumentFor<T>>;
|
|
99
|
-
upsert?: DocumentFor<T>;
|
|
100
|
-
} | {
|
|
101
|
-
doc?: DeepPartial<DocumentFor<T>>;
|
|
102
|
-
upsert: DocumentFor<T>;
|
|
103
|
-
});
|
|
104
|
-
type BulkRequest<T extends IndexDefinition> = Omit<API.Bulk_Request, 'index' | 'body' | '_source_excludes' | '_source_includes'> & {
|
|
105
|
-
index: T['index'];
|
|
106
|
-
body: BulkRequestBody<T>;
|
|
107
|
-
_source_excludes?: NestedLeafPaths<T> | Types.Common.Fields;
|
|
108
|
-
_source_includes?: NestedLeafPaths<T> | Types.Common.Fields;
|
|
109
|
-
};
|
|
110
|
-
type BulkRequestBody<T extends IndexDefinition> = (OperationContainer<T> | UpdateAction<T> | DocumentFor<T>)[];
|
|
111
|
-
type ResponseItem<T extends IndexDefinition> = Omit<Types.Core_Bulk.ResponseItem, '_index'> & {
|
|
112
|
-
_index: T['index'];
|
|
113
|
-
};
|
|
114
|
-
type CustomOperation = string;
|
|
115
|
-
type BulkOperation = 'index' | 'update' | 'delete' | 'create' | CustomOperation;
|
|
116
|
-
type BulkResponseBody<T extends IndexDefinition> = Omit<API.Bulk_ResponseBody, 'items'> & {
|
|
117
|
-
items: Record<BulkOperation, ResponseItem<T>>[];
|
|
118
|
-
};
|
|
119
|
-
type BulkResponse<T extends IndexDefinition> = Omit<API.Bulk_ResponseBody, 'body'> & {
|
|
120
|
-
body: BulkResponseBody<T>;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
type BoolQuery<T> = Omit<Types.Common_QueryDsl.BoolQuery, 'must' | 'should' | 'filter' | 'must_not'> & {
|
|
124
|
-
must?: QueryContainer<T>[];
|
|
125
|
-
should?: QueryContainer<T>[];
|
|
126
|
-
filter?: QueryContainer<T>[];
|
|
127
|
-
must_not?: QueryContainer<T>[];
|
|
128
|
-
};
|
|
129
|
-
type BoostingQuery<T> = Omit<Types.Common_QueryDsl.BoostingQuery, 'positive' | 'negative'> & {
|
|
130
|
-
positive: QueryContainer<T>;
|
|
131
|
-
negative: QueryContainer<T>;
|
|
132
|
-
};
|
|
133
|
-
type CombinedFieldsQuery<T> = Omit<Types.Common_QueryDsl.CombinedFieldsQuery, 'fields'> & {
|
|
134
|
-
fields: NestedPaths<T>[];
|
|
135
|
-
};
|
|
136
|
-
type CommonTermsQuery = Types.Common_QueryDsl.CommonTermsQuery;
|
|
137
|
-
type ConstantScoreQuery<T> = Omit<Types.Common_QueryDsl.ConstantScoreQuery, 'filter'> & {
|
|
138
|
-
filter: QueryContainer<T>;
|
|
139
|
-
};
|
|
140
|
-
type DecayFunction = Types.Common_QueryDsl.DecayFunction;
|
|
141
|
-
type DecayFunctionBase = Types.Common_QueryDsl.DecayFunctionBase;
|
|
142
|
-
type DisMaxQuery<T> = Omit<Types.Common_QueryDsl.DisMaxQuery, 'queries'> & {
|
|
143
|
-
queries: QueryContainer<T>[];
|
|
144
|
-
};
|
|
145
|
-
type DistanceFeatureQuery<T> = Omit<Types.Common_QueryDsl.DistanceFeatureQuery, 'field'> & {
|
|
146
|
-
field: NestedPaths<T>;
|
|
147
|
-
};
|
|
148
|
-
type ExistsQuery<T> = Omit<Types.Common_QueryDsl.ExistsQuery, 'field'> & {
|
|
149
|
-
field: NestedPaths<T>;
|
|
150
|
-
};
|
|
151
|
-
type FieldAndFormat<T> = Omit<Types.Common_QueryDsl.FieldAndFormat, 'field'> & {
|
|
152
|
-
field: NestedPaths<T>;
|
|
153
|
-
};
|
|
154
|
-
type FieldQuery<T, K> = Partial<Record<NestedLeafPaths<T> | BuiltinKeys, K>>;
|
|
155
|
-
type FieldValueFactorScoreFunction<T> = Omit<Types.Common_QueryDsl.FieldValueFactorScoreFunction, 'field'> & {
|
|
156
|
-
field: NestedPaths<T>;
|
|
157
|
-
};
|
|
158
|
-
type FunctionBoostMode = Types.Common_QueryDsl.FunctionBoostMode;
|
|
159
|
-
type FunctionScoreQuery<T> = Omit<Types.Common_QueryDsl.FunctionScoreQuery, 'query'> & {
|
|
160
|
-
query?: QueryContainer<T> | undefined;
|
|
161
|
-
};
|
|
162
|
-
type FuzzyQuery = Types.Common_QueryDsl.FuzzyQuery;
|
|
163
|
-
type GeoBoundingBoxQuery = Types.Common_QueryDsl.GeoBoundingBoxQuery;
|
|
164
|
-
type GeoDistanceQuery = Types.Common_QueryDsl.GeoDistanceQuery;
|
|
165
|
-
type GeoExecution = Types.Common_QueryDsl.GeoExecution;
|
|
166
|
-
type GeoPolygonQuery<T> = Omit<Types.Common_QueryDsl.GeoPolygonQuery, 'field'> & {
|
|
167
|
-
field: NestedPaths<T>;
|
|
168
|
-
};
|
|
169
|
-
type GeoShapeQuery<T> = Omit<Types.Common_QueryDsl.GeoShapeQuery, 'ignore_unmapped' | 'field'> & {
|
|
170
|
-
field: NestedPaths<T>;
|
|
171
|
-
};
|
|
172
|
-
type GeoValidationMethod = Types.Common_QueryDsl.GeoValidationMethod;
|
|
173
|
-
type HasChildQuery<T> = Omit<Types.Common_QueryDsl.HasChildQuery, 'query'> & {
|
|
174
|
-
query: QueryContainer<T>;
|
|
175
|
-
};
|
|
176
|
-
type HasParentQuery<T> = Omit<Types.Common_QueryDsl.HasParentQuery, 'query'> & {
|
|
177
|
-
query: QueryContainer<T>;
|
|
178
|
-
};
|
|
179
|
-
type HybridQuery<T> = Omit<Types.Common_QueryDsl.HybridQuery, 'queries'> & {
|
|
180
|
-
queries?: QueryContainer<T>[];
|
|
181
|
-
};
|
|
182
|
-
type IdsQuery = Types.Common_QueryDsl.IdsQuery;
|
|
183
|
-
type IntervalsQuery = Types.Common_QueryDsl.IntervalsQuery;
|
|
184
|
-
type KnnQuery<T> = Omit<Types.Common_QueryDsl.KnnQuery, 'filter'> & {
|
|
185
|
-
filter?: QueryContainer<T>[];
|
|
186
|
-
};
|
|
187
|
-
type Like = Types.Common_QueryDsl.Like;
|
|
188
|
-
type LikeDocument = Types.Common_QueryDsl.LikeDocument;
|
|
189
|
-
type MatchAllQuery = Types.Common_QueryDsl.MatchAllQuery;
|
|
190
|
-
type MatchBoolPrefixQuery<T> = Omit<Types.Common_QueryDsl.MatchBoolPrefixQuery, 'query' | 'fields'> & {
|
|
191
|
-
fields: NestedPaths<T>[];
|
|
192
|
-
query: string;
|
|
193
|
-
};
|
|
194
|
-
type MatchNoneQuery = Types.Common_QueryDsl.MatchNoneQuery;
|
|
195
|
-
type MatchPhrasePrefixQuery<T> = Omit<Types.Common_QueryDsl.MatchPhrasePrefixQuery, 'query' | 'field'> & {
|
|
196
|
-
field: NestedPaths<T>;
|
|
197
|
-
query: string;
|
|
198
|
-
};
|
|
199
|
-
type MatchPhraseQuery<T> = Omit<Types.Common_QueryDsl.MatchPhraseQuery, 'query' | 'field'> & {
|
|
200
|
-
field: NestedPaths<T>;
|
|
201
|
-
query: string;
|
|
202
|
-
};
|
|
203
|
-
type MatchQuery = FieldValue | Types.Common_QueryDsl.MatchQuery;
|
|
204
|
-
type MoreLikeThisQuery<T> = Omit<Types.Common_QueryDsl.MoreLikeThisQuery, 'fields'> & {
|
|
205
|
-
fields?: NestedPaths<T>[];
|
|
206
|
-
};
|
|
207
|
-
type MultiMatchQuery<T> = Omit<Types.Common_QueryDsl.MultiMatchQuery, 'fields'> & {
|
|
208
|
-
fields?: NestedPaths<T>[];
|
|
209
|
-
};
|
|
210
|
-
type NestedQuery<T> = Omit<Types.Common_QueryDsl.NestedQuery, 'query' | 'path'> & {
|
|
211
|
-
path: NestedPaths<T>;
|
|
212
|
-
query: QueryContainer<T>;
|
|
213
|
-
};
|
|
214
|
-
type NeuralQuery<T> = Omit<Types.Common_QueryDsl.NeuralQuery, 'filter'> & {
|
|
215
|
-
filter?: QueryContainer<T>;
|
|
216
|
-
};
|
|
217
|
-
type NumberRangeQueryParameters<T> = Omit<Types.Common_QueryDsl.NumberRangeQueryParameters, 'field'> & {
|
|
218
|
-
field: NestedPaths<T>;
|
|
219
|
-
};
|
|
220
|
-
type ParentIdQuery = Types.Common_QueryDsl.ParentIdQuery;
|
|
221
|
-
type PercolateQuery<T> = Omit<Types.Common_QueryDsl.PercolateQuery, 'field'> & {
|
|
222
|
-
field: NestedPaths<T>;
|
|
223
|
-
};
|
|
224
|
-
type PinnedQuery = Types.Common_QueryDsl.PinnedQuery;
|
|
225
|
-
type PrefixQuery<T> = Omit<Types.Common_QueryDsl.PrefixQuery, 'value' | 'field'> & {
|
|
226
|
-
field: NestedPaths<T>;
|
|
227
|
-
value: MapOpenSearchTypes<T>;
|
|
228
|
-
};
|
|
229
|
-
type QueryContainer<T> = Omit<Types.Common_QueryDsl.QueryContainer, 'bool' | 'boosting' | 'combined_fields' | 'common' | 'constant_score' | 'dis_max' | 'distance_feature' | 'exists' | 'function_score' | 'fuzzy' | 'geo_bounding_box' | 'geo_distance' | 'geo_polygon' | 'geo_shape' | 'has_child' | 'has_parent' | 'hybrid' | 'ids' | 'intervals' | 'knn' | 'match' | 'match_all' | 'match_bool_prefix' | 'match_none' | 'match_phrase' | 'match_phrase_prefix' | 'more_like_this' | 'multi_match' | 'nested' | 'neural' | 'parent_id' | 'percolate' | 'pinned' | 'prefix' | 'query_string' | 'range' | 'rank_feature' | 'regexp' | 'script' | 'script_score' | 'simple_query_string' | 'span_containing' | 'span_first' | 'span_multi' | 'span_near' | 'span_not' | 'span_or' | 'span_term' | 'span_within' | 'term' | 'terms' | 'terms_set' | 'type' | 'wildcard' | 'wrapper' | 'xy_shape'> & {
|
|
230
|
-
bool?: BoolQuery<T>;
|
|
231
|
-
boosting?: BoostingQuery<T>;
|
|
232
|
-
combined_fields?: CombinedFieldsQuery<T>;
|
|
233
|
-
common?: FieldQuery<T, Types.Common_QueryDsl.CommonTermsQuery>;
|
|
234
|
-
constant_score?: ConstantScoreQuery<T>;
|
|
235
|
-
dis_max?: DisMaxQuery<T>;
|
|
236
|
-
distance_feature?: DistanceFeatureQuery<T>;
|
|
237
|
-
exists?: ExistsQuery<T>;
|
|
238
|
-
function_score?: FunctionScoreQuery<T>;
|
|
239
|
-
fuzzy?: FieldQuery<T, Types.Common_QueryDsl.FuzzyQuery>;
|
|
240
|
-
geo_bounding_box?: GeoBoundingBoxQuery;
|
|
241
|
-
geo_distance?: GeoDistanceQuery;
|
|
242
|
-
geo_polygon?: GeoPolygonQuery<T>;
|
|
243
|
-
geo_shape?: GeoShapeQuery<T>;
|
|
244
|
-
has_child?: HasChildQuery<T>;
|
|
245
|
-
has_parent?: HasParentQuery<T>;
|
|
246
|
-
hybrid?: HybridQuery<T>;
|
|
247
|
-
ids?: IdsQuery;
|
|
248
|
-
intervals?: FieldQuery<T, IntervalsQuery>;
|
|
249
|
-
knn?: FieldQuery<T, KnnQuery<T>>;
|
|
250
|
-
match?: FieldQuery<T, MatchQuery>;
|
|
251
|
-
match_all?: MatchAllQuery;
|
|
252
|
-
match_bool_prefix?: FieldQuery<T, MatchBoolPrefixQuery<T>>;
|
|
253
|
-
match_none?: MatchNoneQuery;
|
|
254
|
-
match_phrase?: FieldQuery<T, MatchPhraseQuery<T>>;
|
|
255
|
-
match_phrase_prefix?: FieldQuery<T, MatchPhrasePrefixQuery<T>>;
|
|
256
|
-
more_like_this?: MoreLikeThisQuery<T>;
|
|
257
|
-
multi_match?: MultiMatchQuery<T>;
|
|
258
|
-
nested?: NestedQuery<T>;
|
|
259
|
-
neural?: FieldQuery<T, NeuralQuery<T>>;
|
|
260
|
-
parent_id?: ParentIdQuery;
|
|
261
|
-
percolate?: PercolateQuery<T>;
|
|
262
|
-
pinned?: PinnedQuery;
|
|
263
|
-
prefix?: FieldQuery<T, PrefixQuery<T>>;
|
|
264
|
-
query_string?: QueryStringQuery;
|
|
265
|
-
range?: FieldQuery<T, RangeQuery<T>>;
|
|
266
|
-
rank_feature?: RankFeatureQuery;
|
|
267
|
-
regexp?: FieldQuery<T, RegexpQuery<T>>;
|
|
268
|
-
script?: ScriptQuery;
|
|
269
|
-
script_score?: ScriptScoreQuery<T>;
|
|
270
|
-
simple_query_string?: SimpleQueryStringQuery<T>;
|
|
271
|
-
span_containing?: SpanContainingQuery<T>;
|
|
272
|
-
span_first?: SpanFirstQuery<T>;
|
|
273
|
-
span_multi?: SpanMultiTermQuery<T>;
|
|
274
|
-
span_near?: SpanNearQuery<T>;
|
|
275
|
-
span_not?: SpanNotQuery<T>;
|
|
276
|
-
span_or?: SpanOrQuery<T>;
|
|
277
|
-
span_term?: FieldQuery<T, SpanTermQuery<T>>;
|
|
278
|
-
span_within?: SpanWithinQuery<T>;
|
|
279
|
-
term?: FieldQuery<T, TermQuery<T>>;
|
|
280
|
-
terms?: TermsQuery<T>;
|
|
281
|
-
terms_set?: FieldQuery<T, TermsSetQuery<T>>;
|
|
282
|
-
type?: TypeQuery;
|
|
283
|
-
wildcard?: FieldQuery<T, WildcardQuery<T>>;
|
|
284
|
-
wrapper?: WrapperQuery;
|
|
285
|
-
xy_shape?: XyShapeQuery<T>;
|
|
286
|
-
};
|
|
287
|
-
type QueryStringQuery = Types.Common_QueryDsl.QueryStringQuery;
|
|
288
|
-
type RangeQuery<T> = Omit<Types.Common_QueryDsl.RangeQuery, 'field'> & {
|
|
289
|
-
field: NestedPaths<T>;
|
|
290
|
-
};
|
|
291
|
-
type RankFeatureQuery = Types.Common_QueryDsl.RankFeatureQuery;
|
|
292
|
-
type RegexpQuery<T> = Omit<Types.Common_QueryDsl.RegexpQuery, 'value' | 'field'> & {
|
|
293
|
-
field: NestedPaths<T>;
|
|
294
|
-
value: MapOpenSearchTypes<T>;
|
|
295
|
-
};
|
|
296
|
-
type ScriptQuery = Types.Common_QueryDsl.ScriptQuery;
|
|
297
|
-
type ScriptScoreQuery<T> = Omit<Types.Common_QueryDsl.ScriptScoreQuery, 'query'> & {
|
|
298
|
-
query?: QueryContainer<T>;
|
|
299
|
-
};
|
|
300
|
-
type SimpleQueryStringQuery<T> = Omit<Types.Common_QueryDsl.SimpleQueryStringQuery, 'fields'> & {
|
|
301
|
-
fields: NestedLeafPaths<T>[];
|
|
302
|
-
};
|
|
303
|
-
type SpanQuery<T> = Omit<Types.Common_QueryDsl.SpanQuery, 'field_masking_span' | 'span_containing' | 'span_first' | 'span_multi' | 'span_near' | 'span_not' | 'span_or' | 'span_term' | 'span_within'> & {
|
|
304
|
-
field_masking_span?: SpanFieldMaskingQuery<T>;
|
|
305
|
-
span_containing?: SpanContainingQuery<T>;
|
|
306
|
-
span_first?: SpanFirstQuery<T>;
|
|
307
|
-
span_multi?: SpanMultiTermQuery<T>;
|
|
308
|
-
span_near?: SpanNearQuery<T>;
|
|
309
|
-
span_not?: SpanNotQuery<T>;
|
|
310
|
-
span_or?: SpanOrQuery<T>;
|
|
311
|
-
span_term?: Record<NestedPaths<T>, SpanTermQuery<T>>;
|
|
312
|
-
span_within?: SpanWithinQuery<T>;
|
|
313
|
-
};
|
|
314
|
-
type SpanContainingQuery<T> = Omit<Types.Common_QueryDsl.SpanContainingQuery, 'big' | 'little'> & {
|
|
315
|
-
big: SpanQuery<T>;
|
|
316
|
-
little: SpanQuery<T>;
|
|
317
|
-
};
|
|
318
|
-
type SpanFieldMaskingQuery<T> = Omit<Types.Common_QueryDsl.SpanFieldMaskingQuery, 'field' | 'query'> & {
|
|
319
|
-
field: NestedPaths<T>;
|
|
320
|
-
query: SpanQuery<T>;
|
|
321
|
-
};
|
|
322
|
-
type SpanFirstQuery<T> = Omit<Types.Common_QueryDsl.SpanFirstQuery, 'match'> & {
|
|
323
|
-
match: SpanQuery<T>;
|
|
324
|
-
};
|
|
325
|
-
type SpanMultiTermQuery<T> = Omit<Types.Common_QueryDsl.SpanMultiTermQuery, 'match'> & {
|
|
326
|
-
match: QueryContainer<T>;
|
|
327
|
-
};
|
|
328
|
-
type SpanNearQuery<T> = Omit<Types.Common_QueryDsl.SpanNearQuery, 'clauses'> & {
|
|
329
|
-
clauses: SpanQuery<T>[];
|
|
330
|
-
};
|
|
331
|
-
type SpanNotQuery<T> = Omit<Types.Common_QueryDsl.SpanNotQuery, 'include' | 'exclude'> & {
|
|
332
|
-
include: SpanQuery<T>;
|
|
333
|
-
exclude: SpanQuery<T>;
|
|
334
|
-
};
|
|
335
|
-
type SpanOrQuery<T> = Omit<Types.Common_QueryDsl.SpanOrQuery, 'clauses'> & {
|
|
336
|
-
clauses: SpanQuery<T>[];
|
|
337
|
-
};
|
|
338
|
-
type SpanTermQuery<T> = Omit<Types.Common_QueryDsl.SpanTermQuery, 'value' | 'field'> & {
|
|
339
|
-
field: NestedPaths<T>;
|
|
340
|
-
value: MapOpenSearchTypes<T>;
|
|
341
|
-
};
|
|
342
|
-
type SpanWithinQuery<T> = Omit<Types.Common_QueryDsl.SpanWithinQuery, 'big' | 'little'> & {
|
|
343
|
-
big: SpanQuery<T>;
|
|
344
|
-
little: SpanQuery<T>;
|
|
345
|
-
};
|
|
346
|
-
type TermQuery<T> = Omit<Types.Common_QueryDsl.TermQuery, 'value' | 'field'> & {
|
|
347
|
-
field: NestedPaths<T>;
|
|
348
|
-
value: MapOpenSearchTypes<T>;
|
|
349
|
-
};
|
|
350
|
-
type TermsQuery<T> = Omit<Types.Common_QueryDsl.TermsQuery, 'terms' | 'field'> & {
|
|
351
|
-
field: NestedPaths<T>;
|
|
352
|
-
terms: FieldValue[];
|
|
353
|
-
};
|
|
354
|
-
type TermsSetQuery<T> = Omit<Types.Common_QueryDsl.TermsSetQuery, 'terms' | 'field'> & {
|
|
355
|
-
field: NestedPaths<T>;
|
|
356
|
-
terms: FieldValue[];
|
|
357
|
-
};
|
|
358
|
-
type TypeQuery = Types.Common_QueryDsl.TypeQuery;
|
|
359
|
-
type WildcardQuery<T> = Omit<Types.Common_QueryDsl.WildcardQuery, 'value' | 'field'> & {
|
|
360
|
-
field: NestedPaths<T>;
|
|
361
|
-
value: MapOpenSearchTypes<T>;
|
|
362
|
-
};
|
|
363
|
-
type WrapperQuery = Types.Common_QueryDsl.WrapperQuery;
|
|
364
|
-
type XyShapeQuery<T> = Omit<Types.Common_QueryDsl.XyShapeQuery, 'field'> & {
|
|
365
|
-
field: NestedPaths<T>;
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
type FieldCollapse<T> = Omit<Types.Core_Search.FieldCollapse, 'field'> & {
|
|
369
|
-
field: NestedPaths<T>;
|
|
370
|
-
};
|
|
371
|
-
type Highlight<T> = Omit<Types.Core_Search.Highlight, 'fields'> & {
|
|
372
|
-
fields: FieldQuery<T, Types.Core_Search.HighlightField>;
|
|
373
|
-
};
|
|
374
|
-
type Hit<T extends IndexDefinition> = Omit<Types.Core_Search.Hit, '_source'> & {
|
|
375
|
-
_source: DocumentFor<T>;
|
|
376
|
-
};
|
|
377
|
-
type HitsMetadata<T extends IndexDefinition> = Omit<Types.Core_Search.HitsMetadata, 'hits'> & {
|
|
378
|
-
hits: Hit<T>[];
|
|
379
|
-
};
|
|
380
|
-
type SourceConfig<T> = boolean | SourceFilter<T>;
|
|
381
|
-
type SourceFilter<T> = NestedPaths<T>[] | {
|
|
382
|
-
excludes?: NestedPaths<T>[];
|
|
383
|
-
includes?: NestedPaths<T>[];
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
type SearchRequest<T extends IndexDefinition> = Omit<API.Search_Request, 'body' | 'index'> & {
|
|
387
|
-
index: T['index'];
|
|
388
|
-
body: SearchRequestBody<T>;
|
|
389
|
-
};
|
|
390
|
-
type SearchRequestBody<T extends IndexDefinition> = Omit<API.Search_RequestBody, 'query' | 'collapse' | 'highlight' | 'sort' | '_source'> & {
|
|
391
|
-
query?: QueryContainer<MapQueryProperties<T>>;
|
|
392
|
-
collapse?: FieldCollapse<MapQueryProperties<T>>;
|
|
393
|
-
highlight?: Highlight<MapQueryProperties<T>>;
|
|
394
|
-
sort?: Sort<MapQueryProperties<T>>;
|
|
395
|
-
_source?: SourceConfig<MapQueryProperties<T>>;
|
|
396
|
-
};
|
|
397
|
-
type SearchResponse<T extends IndexDefinition> = Omit<API.Search_Response, 'body'> & {
|
|
398
|
-
body: SearchResponseBody<T>;
|
|
399
|
-
};
|
|
400
|
-
type SearchResponseBody<T extends IndexDefinition> = Omit<API.Search_ResponseBody, 'hits'> & {
|
|
401
|
-
hits: HitsMetadata<T>;
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
interface IndexRequest<T> extends Omit<API.Index_Request, 'body' | 'index'> {
|
|
405
|
-
index: T extends {
|
|
406
|
-
index: infer I;
|
|
407
|
-
} ? I : never;
|
|
408
|
-
body: T extends {
|
|
409
|
-
body: {
|
|
410
|
-
mappings: {
|
|
411
|
-
properties: infer P;
|
|
412
|
-
};
|
|
413
|
-
};
|
|
414
|
-
} ? MapOpenSearchTypes<P> : never;
|
|
415
|
-
}
|
|
416
|
-
interface IndexResponse extends API.Index_Response {
|
|
417
|
-
}
|
|
418
|
-
type IndicesExistsRequest<T extends IndexDefinition> = Omit<API.Indices_Exists_Request, 'index'> & {
|
|
419
|
-
index: Extract<T['index'], string>;
|
|
420
|
-
};
|
|
421
|
-
|
|
422
|
-
type TypedIndices = Omit<Indices, 'exists'> & {
|
|
423
|
-
exists<T extends IndexDefinition>(params: IndicesExistsRequest<T>, options?: TransportRequestOptions): TransportRequestPromise<API.Indices_Exists_Response>;
|
|
424
|
-
};
|
|
425
|
-
/**
|
|
426
|
-
* ✅ Constructor type that ensures `new OpenSearchClient()` works.
|
|
427
|
-
* - This type is necessary because `OpenSearchClient` is actually a function (not a class).
|
|
428
|
-
*/
|
|
429
|
-
type OpenSearchClientConstructor = new (...args: ConstructorParameters<typeof Client>) => OpenSearchClient;
|
|
430
|
-
/**
|
|
431
|
-
* ✅ Custom interface that extends `Client`, but replaces the `search()` method signature.
|
|
432
|
-
* - Uses `Omit<Client, "search">` to remove `search()` from `Client`.
|
|
433
|
-
* - Defines a new `search<T>()` method with stricter type safety.
|
|
434
|
-
*/
|
|
435
|
-
interface OpenSearchClient extends Omit<Client, 'search' | 'index' | 'bulk' | 'indices'> {
|
|
436
|
-
search<T extends IndexDefinition>(params: SearchRequest<T>, options?: TransportRequestOptions): TransportRequestPromise<SearchResponse<T>>;
|
|
437
|
-
index<T extends IndexDefinition>(params: IndexRequest<T>, options?: TransportRequestOptions): TransportRequestPromise<API.Index_Response>;
|
|
438
|
-
bulk<T extends IndexDefinition>(params: BulkRequest<T>, options?: TransportRequestOptions): TransportRequestPromise<BulkResponse<T>>;
|
|
439
|
-
indices: TypedIndices;
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* ✅ A function that behaves like a class constructor.
|
|
443
|
-
* - Instantiates a new `Client` internally.
|
|
444
|
-
* - Casts the instance to `OpenSearchClient` so TypeScript recognizes the new `search<T>()` signature.
|
|
445
|
-
* - The `as unknown as` trick ensures `new OpenSearchClient()` is valid.
|
|
446
|
-
*/
|
|
447
|
-
declare const OpenSearchClient: OpenSearchClientConstructor;
|
|
448
|
-
|
|
449
|
-
type IdFunction<T extends IndexDefinition> = (doc: DocumentFor<T>) => Types.Common.Id;
|
|
450
|
-
/**
|
|
451
|
-
* Constructs a bulk request payload for indexing documents.
|
|
452
|
-
*
|
|
453
|
-
* For each document in the provided array, this helper creates a two‑line bulk operation:
|
|
454
|
-
* 1. An action object for an index operation. If an id generator is provided, its result is used as _id.
|
|
455
|
-
* 2. The document itself.
|
|
456
|
-
*
|
|
457
|
-
* @param index - The name of the index.
|
|
458
|
-
* @param docs - An array of documents to insert.
|
|
459
|
-
* @param idFn - Optional function that returns an _id for a given document.
|
|
460
|
-
* @returns A BulkRequest payload for insert operations.
|
|
461
|
-
*/
|
|
462
|
-
declare function bulkIndex<T extends IndexDefinition>(index: T['index'], docs: DocumentFor<T>[], idFn?: IdFunction<T>): BulkRequest<T>;
|
|
463
|
-
/**
|
|
464
|
-
* Constructs a bulk request payload for creating documents.
|
|
465
|
-
*
|
|
466
|
-
* For each document in the provided array, this helper creates a two‑line bulk operation:
|
|
467
|
-
* 1. An action object for a create operation with a generated _id.
|
|
468
|
-
* 2. The document itself.
|
|
469
|
-
*
|
|
470
|
-
* @param index - The name of the index.
|
|
471
|
-
* @param docs - An array of documents to create.
|
|
472
|
-
* @param idFn - A function that returns a unique _id for each document.
|
|
473
|
-
* @returns A BulkRequest payload for create operations.
|
|
474
|
-
*/
|
|
475
|
-
declare function bulkCreate<T extends IndexDefinition>(index: T['index'], docs: DocumentFor<T>[], idFn: IdFunction<T>): BulkRequest<T>;
|
|
476
|
-
/**
|
|
477
|
-
* Constructs a bulk request payload for update operations.
|
|
478
|
-
*
|
|
479
|
-
* This helper takes an array of update actions (of type UpdateAction<T>),
|
|
480
|
-
* splits each into its action metadata and payload (with the `doc` and/or `upsert` properties),
|
|
481
|
-
* and returns a BulkRequest payload formatted as a flat array.
|
|
482
|
-
*
|
|
483
|
-
* @param index - The name of the index.
|
|
484
|
-
* @param updates - An array of update actions.
|
|
485
|
-
* @param idFn - A function that returns a unique _id for each document.
|
|
486
|
-
* @returns A BulkRequest payload for update operations.
|
|
487
|
-
*/
|
|
488
|
-
declare function bulkUpdate<T extends IndexDefinition>(index: T['index'], updates: UpdateAction<T>[], idFn: IdFunction<T>): BulkRequest<T>;
|
|
489
|
-
/**
|
|
490
|
-
* Constructs a bulk request payload for deleting documents.
|
|
491
|
-
*
|
|
492
|
-
* For each document in the provided array, this helper creates a single‑line bulk operation:
|
|
493
|
-
* { delete: { _id: <id> } }
|
|
494
|
-
* The provided id generator function is used to compute the _id for each document.
|
|
495
|
-
*
|
|
496
|
-
* @param index - The name of the index.
|
|
497
|
-
* @param docs - An array of documents to delete.
|
|
498
|
-
* @param idFn - A function that returns the _id for a given document.
|
|
499
|
-
* @returns A BulkRequest payload for delete operations.
|
|
500
|
-
*/
|
|
501
|
-
declare function bulkDelete<T extends IndexDefinition>(index: T['index'], ids: Types.Common.Id[]): BulkRequest<T>;
|
|
502
|
-
|
|
503
|
-
export { type BoolQuery, type BoostingQuery, type BulkRequest, type BulkResponse, type CombinedFieldsQuery, type CommonTermsQuery, type ConstantScoreQuery, type DecayFunction, type DecayFunctionBase, type DeepPartial, type DisMaxQuery, type DistanceFeatureQuery, type DocumentFor, type ExistsQuery, type FieldAndFormat, type FieldQuery, type FieldValueFactorScoreFunction, type FunctionBoostMode, type FunctionScoreQuery, type FuzzyQuery, type GeoBoundingBoxQuery, type GeoDistanceQuery, type GeoExecution, type GeoPolygonQuery, type GeoShapeQuery, type GeoValidationMethod, type HasChildQuery, type HasParentQuery, type HybridQuery, type IdFunction, type IdsQuery, type IndexDefinition, type IndexRequest, type IndexResponse, type IntervalsQuery, type KnnQuery, type Like, type LikeDocument, type MatchAllQuery, type MatchBoolPrefixQuery, type MatchNoneQuery, type MatchPhrasePrefixQuery, type MatchPhraseQuery, type MatchQuery, type MoreLikeThisQuery, type MultiMatchQuery, type NestedQuery, type NeuralQuery, type NumberRangeQueryParameters, OpenSearchClient, type ParentIdQuery, type PercolateQuery, type PinnedQuery, type PrefixQuery, type Primitive, type QueryContainer, type QueryStringQuery, type RangeQuery, type RankFeatureQuery, type RegexpQuery, type ScriptQuery, type ScriptScoreQuery, type SearchRequest, type SearchResponse, type SimpleQueryStringQuery, type SpanContainingQuery, type SpanFieldMaskingQuery, type SpanFirstQuery, type SpanMultiTermQuery, type SpanNearQuery, type SpanNotQuery, type SpanOrQuery, type SpanQuery, type SpanTermQuery, type SpanWithinQuery, type TermQuery, type TermsQuery, type TermsSetQuery, type TypeQuery, type UpdateAction, type WildcardQuery, type WrapperQuery, type XyShapeQuery, bulkCreate, bulkDelete, bulkIndex, bulkUpdate };
|
package/dist/index.mjs
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// src/client.ts
|
|
2
|
-
import { Client } from "@opensearch-project/opensearch";
|
|
3
|
-
var OpenSearchClient = function(...args) {
|
|
4
|
-
const clientInstance = new Client(...args);
|
|
5
|
-
return clientInstance;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// src/helpers.ts
|
|
9
|
-
function bulkIndex(index, docs, idFn) {
|
|
10
|
-
const body = docs.flatMap((doc) => {
|
|
11
|
-
const op = idFn ? { _id: idFn(doc) } : {};
|
|
12
|
-
return [{ index: op }, doc];
|
|
13
|
-
});
|
|
14
|
-
return { index, body };
|
|
15
|
-
}
|
|
16
|
-
function bulkCreate(index, docs, idFn) {
|
|
17
|
-
const body = docs.flatMap((doc) => {
|
|
18
|
-
const op = { _id: idFn(doc) };
|
|
19
|
-
return [{ create: op }, doc];
|
|
20
|
-
});
|
|
21
|
-
return { index, body };
|
|
22
|
-
}
|
|
23
|
-
function bulkUpdate(index, updates, idFn) {
|
|
24
|
-
const body = updates.flatMap((update) => {
|
|
25
|
-
const op = {
|
|
26
|
-
_id: idFn(update.doc || update.upsert)
|
|
27
|
-
};
|
|
28
|
-
return [{ update: op }, update];
|
|
29
|
-
});
|
|
30
|
-
return { index, body };
|
|
31
|
-
}
|
|
32
|
-
function bulkDelete(index, ids) {
|
|
33
|
-
const body = ids.map((_id) => {
|
|
34
|
-
const op = { _id };
|
|
35
|
-
return { delete: op };
|
|
36
|
-
});
|
|
37
|
-
return { index, body };
|
|
38
|
-
}
|
|
39
|
-
export {
|
|
40
|
-
OpenSearchClient,
|
|
41
|
-
bulkCreate,
|
|
42
|
-
bulkDelete,
|
|
43
|
-
bulkIndex,
|
|
44
|
-
bulkUpdate
|
|
45
|
-
};
|