@backstage/plugin-search-backend-module-elasticsearch 1.5.7-next.1 → 1.6.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 CHANGED
@@ -1,5 +1,34 @@
1
1
  # @backstage/plugin-search-backend-module-elasticsearch
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3109c24: The export for the new backend system at the `/alpha` export is now also available via the main entry point, which means that you can remove the `/alpha` suffix from the import.
8
+
9
+ ### Patch Changes
10
+
11
+ - d78b07c: Align the configuration schema with the docs and actual behavior of the code
12
+ - 4b60e0c: Remove extension points from `/alpha` export, they're available from the main package already
13
+ - 094eaa3: Remove references to in-repo backend-common
14
+ - Updated dependencies
15
+ - @backstage/plugin-search-backend-node@1.3.3
16
+ - @backstage/backend-plugin-api@1.0.1
17
+ - @backstage/config@1.2.0
18
+ - @backstage/integration-aws-node@0.1.12
19
+ - @backstage/plugin-search-common@1.2.14
20
+
21
+ ## 1.5.7-next.2
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies
26
+ - @backstage/backend-plugin-api@1.0.1-next.1
27
+ - @backstage/config@1.2.0
28
+ - @backstage/integration-aws-node@0.1.12
29
+ - @backstage/plugin-search-backend-node@1.3.3-next.2
30
+ - @backstage/plugin-search-common@1.2.14
31
+
3
32
  ## 1.5.7-next.1
4
33
 
5
34
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-search-backend-module-elasticsearch__alpha",
3
- "version": "1.5.7-next.1",
3
+ "version": "1.6.0",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
package/dist/alpha.cjs.js CHANGED
@@ -2,55 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var backendPluginApi = require('@backstage/backend-plugin-api');
6
- var alpha$1 = require('@backstage/plugin-search-backend-node/alpha');
7
- var pluginSearchBackendModuleElasticsearch = require('@backstage/plugin-search-backend-module-elasticsearch');
5
+ var module$1 = require('./module.cjs.js');
8
6
 
9
- const elasticsearchTranslatorExtensionPoint = backendPluginApi.createExtensionPoint({
10
- id: "search.elasticsearchEngine.translator"
11
- });
12
- var alpha = backendPluginApi.createBackendModule({
13
- pluginId: "search",
14
- moduleId: "elasticsearch-engine",
15
- register(env) {
16
- let translator;
17
- env.registerExtensionPoint(elasticsearchTranslatorExtensionPoint, {
18
- setTranslator(newTranslator) {
19
- if (translator) {
20
- throw new Error(
21
- "ElasticSearch query translator may only be set once"
22
- );
23
- }
24
- translator = newTranslator;
25
- }
26
- });
27
- env.registerInit({
28
- deps: {
29
- searchEngineRegistry: alpha$1.searchEngineRegistryExtensionPoint,
30
- logger: backendPluginApi.coreServices.logger,
31
- config: backendPluginApi.coreServices.rootConfig
32
- },
33
- async init({ searchEngineRegistry, logger, config }) {
34
- const baseKey = "search.elasticsearch";
35
- const baseConfig = config.getOptional(baseKey);
36
- if (!baseConfig) {
37
- logger.warn(
38
- 'No configuration found under "search.elasticsearch" key. Skipping search engine inititalization.'
39
- );
40
- return;
41
- }
42
- searchEngineRegistry.setSearchEngine(
43
- await pluginSearchBackendModuleElasticsearch.ElasticSearchSearchEngine.fromConfig({
44
- logger,
45
- config,
46
- translator
47
- })
48
- );
49
- }
50
- });
51
- }
52
- });
7
+ const _feature = module$1.default;
53
8
 
54
- exports.default = alpha;
55
- exports.elasticsearchTranslatorExtensionPoint = elasticsearchTranslatorExtensionPoint;
9
+ exports.default = _feature;
56
10
  //# sourceMappingURL=alpha.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"alpha.cjs.js","sources":["../src/alpha.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n coreServices,\n createBackendModule,\n createExtensionPoint,\n} from '@backstage/backend-plugin-api';\nimport { searchEngineRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha';\nimport {\n ElasticSearchQueryTranslator,\n ElasticSearchSearchEngine,\n} from '@backstage/plugin-search-backend-module-elasticsearch';\n\n/** @alpha */\nexport interface ElasticSearchQueryTranslatorExtensionPoint {\n setTranslator(translator: ElasticSearchQueryTranslator): void;\n}\n\n/**\n * Extension point used to customize the ElasticSearch query translator.\n *\n * @alpha\n */\nexport const elasticsearchTranslatorExtensionPoint =\n createExtensionPoint<ElasticSearchQueryTranslatorExtensionPoint>({\n id: 'search.elasticsearchEngine.translator',\n });\n\n/**\n * Search backend module for the Elasticsearch engine.\n *\n * @alpha\n */\nexport default createBackendModule({\n pluginId: 'search',\n moduleId: 'elasticsearch-engine',\n register(env) {\n let translator: ElasticSearchQueryTranslator | undefined;\n\n env.registerExtensionPoint(elasticsearchTranslatorExtensionPoint, {\n setTranslator(newTranslator) {\n if (translator) {\n throw new Error(\n 'ElasticSearch query translator may only be set once',\n );\n }\n translator = newTranslator;\n },\n });\n\n env.registerInit({\n deps: {\n searchEngineRegistry: searchEngineRegistryExtensionPoint,\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n },\n async init({ searchEngineRegistry, logger, config }) {\n const baseKey = 'search.elasticsearch';\n const baseConfig = config.getOptional(baseKey);\n if (!baseConfig) {\n logger.warn(\n 'No configuration found under \"search.elasticsearch\" key. Skipping search engine inititalization.',\n );\n return;\n }\n\n searchEngineRegistry.setSearchEngine(\n await ElasticSearchSearchEngine.fromConfig({\n logger,\n config,\n translator,\n }),\n );\n },\n });\n },\n});\n"],"names":["createExtensionPoint","createBackendModule","searchEngineRegistryExtensionPoint","coreServices","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AAA;;;;;"}
1
+ {"version":3,"file":"alpha.cjs.js","sources":["../src/alpha.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { default as feature } from './module';\n\n/** @alpha */\nconst _feature = feature;\nexport default _feature;\n"],"names":["feature"],"mappings":";;;;;;AAmBA,MAAM,QAAW,GAAAA;;;;"}
package/dist/alpha.d.ts CHANGED
@@ -1,21 +1,6 @@
1
1
  import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
2
- import { ElasticSearchQueryTranslator } from '@backstage/plugin-search-backend-module-elasticsearch';
3
2
 
4
3
  /** @alpha */
5
- interface ElasticSearchQueryTranslatorExtensionPoint {
6
- setTranslator(translator: ElasticSearchQueryTranslator): void;
7
- }
8
- /**
9
- * Extension point used to customize the ElasticSearch query translator.
10
- *
11
- * @alpha
12
- */
13
- declare const elasticsearchTranslatorExtensionPoint: _backstage_backend_plugin_api.ExtensionPoint<ElasticSearchQueryTranslatorExtensionPoint>;
14
- /**
15
- * Search backend module for the Elasticsearch engine.
16
- *
17
- * @alpha
18
- */
19
- declare const _default: _backstage_backend_plugin_api.BackendFeature;
4
+ declare const _feature: _backstage_backend_plugin_api.BackendFeature;
20
5
 
21
- export { type ElasticSearchQueryTranslatorExtensionPoint, _default as default, elasticsearchTranslatorExtensionPoint };
6
+ export { _feature as default };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ const isOpenSearchCompatible = (opts) => {
4
+ return ["aws", "opensearch"].includes(opts?.provider ?? "");
5
+ };
6
+
7
+ exports.isOpenSearchCompatible = isOpenSearchCompatible;
8
+ //# sourceMappingURL=ElasticSearchClientOptions.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ElasticSearchClientOptions.cjs.js","sources":["../../src/engines/ElasticSearchClientOptions.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type { ConnectionOptions as TLSConnectionOptions } from 'tls';\n\n/**\n * Typeguard to differentiate ElasticSearch client options which are compatible\n * with OpenSearch vs. ElasticSearch clients. Useful when calling the\n * {@link ElasticSearchSearchEngine.newClient} method.\n *\n * @public\n */\nexport const isOpenSearchCompatible = (\n opts: ElasticSearchClientOptions,\n): opts is OpenSearchElasticSearchClientOptions => {\n return ['aws', 'opensearch'].includes(opts?.provider ?? '');\n};\n\n/**\n * Options used to configure the `@elastic/elasticsearch` client or the\n * `@opensearch-project/opensearch` client, depending on the given config. It\n * will be passed as an argument to the\n * {@link ElasticSearchSearchEngine.newClient} method.\n *\n * @public\n */\nexport type ElasticSearchClientOptions =\n | ElasticSearchElasticSearchClientOptions\n | OpenSearchElasticSearchClientOptions;\n\n/**\n * Options used to configure the `@opensearch-project/opensearch` client.\n *\n * They are drawn from the `ClientOptions` class of `@opensearch-project/opensearch`,\n * but are maintained separately so that this interface is not coupled to it.\n *\n * @public\n */\nexport interface OpenSearchElasticSearchClientOptions\n extends BaseElasticSearchClientOptions {\n provider?: 'aws' | 'opensearch';\n region?: string;\n service?: 'es' | 'aoss';\n auth?: OpenSearchAuth;\n connection?: OpenSearchConnectionConstructor;\n node?: string | string[] | OpenSearchNodeOptions | OpenSearchNodeOptions[];\n nodes?: string | string[] | OpenSearchNodeOptions | OpenSearchNodeOptions[];\n}\n\n/**\n * Options used to configure the `@elastic/elasticsearch` client.\n *\n * They are drawn from the `ClientOptions` class of `@elastic/elasticsearch`,\n * but are maintained separately so that this interface is not coupled to it.\n *\n * @public\n */\nexport interface ElasticSearchElasticSearchClientOptions\n extends BaseElasticSearchClientOptions {\n provider?: 'elastic';\n auth?: ElasticSearchAuth;\n Connection?: ElasticSearchConnectionConstructor;\n node?:\n | string\n | string[]\n | ElasticSearchNodeOptions\n | ElasticSearchNodeOptions[];\n nodes?:\n | string\n | string[]\n | ElasticSearchNodeOptions\n | ElasticSearchNodeOptions[];\n cloud?: {\n id: string;\n username?: string;\n password?: string;\n };\n}\n\n/**\n * Base client options that are shared across `@opensearch-project/opensearch`\n * and `@elastic/elasticsearch` clients.\n *\n * @public\n */\nexport interface BaseElasticSearchClientOptions {\n Transport?: ElasticSearchTransportConstructor;\n maxRetries?: number;\n requestTimeout?: number;\n pingTimeout?: number;\n sniffInterval?: number | boolean;\n sniffOnStart?: boolean;\n sniffEndpoint?: string;\n sniffOnConnectionFault?: boolean;\n resurrectStrategy?: 'ping' | 'optimistic' | 'none';\n suggestCompression?: boolean;\n compression?: 'gzip';\n ssl?: TLSConnectionOptions;\n agent?: ElasticSearchAgentOptions | ((opts?: any) => unknown) | false;\n nodeFilter?: (connection: any) => boolean;\n nodeSelector?: ((connections: any[]) => any) | string;\n headers?: Record<string, any>;\n opaqueIdPrefix?: string;\n name?: string | symbol;\n proxy?: string | URL;\n enableMetaHeader?: boolean;\n disablePrototypePoisoningProtection?: boolean | 'proto' | 'constructor';\n}\n\n/**\n * @public\n */\nexport type OpenSearchAuth = {\n username: string;\n password: string;\n};\n\n/**\n * @public\n */\nexport type ElasticSearchAuth =\n | OpenSearchAuth\n | {\n apiKey:\n | string\n | {\n id: string;\n api_key: string;\n };\n };\n\n/**\n * @public\n */\nexport interface ElasticSearchNodeOptions {\n url: URL;\n id?: string;\n agent?: ElasticSearchAgentOptions;\n ssl?: TLSConnectionOptions;\n headers?: Record<string, any>;\n roles?: {\n master: boolean;\n data: boolean;\n ingest: boolean;\n ml: boolean;\n };\n}\n\n/**\n * @public\n */\nexport interface OpenSearchNodeOptions {\n url: URL;\n id?: string;\n agent?: ElasticSearchAgentOptions;\n ssl?: TLSConnectionOptions;\n headers?: Record<string, any>;\n roles?: {\n master: boolean;\n data: boolean;\n ingest: boolean;\n };\n}\n\n/**\n * @public\n */\nexport interface ElasticSearchAgentOptions {\n keepAlive?: boolean;\n keepAliveMsecs?: number;\n maxSockets?: number;\n maxFreeSockets?: number;\n}\n\n/**\n * @public\n */\nexport interface ElasticSearchConnectionConstructor {\n new (opts?: any): any;\n statuses: {\n ALIVE: string;\n DEAD: string;\n };\n roles: {\n MASTER: string;\n DATA: string;\n INGEST: string;\n ML: string;\n };\n}\n\n/**\n * @public\n */\nexport interface OpenSearchConnectionConstructor {\n new (opts?: any): any;\n statuses: {\n ALIVE: string;\n DEAD: string;\n };\n roles: {\n MASTER: string;\n DATA: string;\n INGEST: string;\n };\n}\n\n/**\n * @public\n */\nexport interface ElasticSearchTransportConstructor {\n new (opts?: any): any;\n sniffReasons: {\n SNIFF_ON_START: string;\n SNIFF_INTERVAL: string;\n SNIFF_ON_CONNECTION_FAULT: string;\n DEFAULT: string;\n };\n}\n\n// todo(iamEAP) implement canary types to ensure we remain compatible through upgrades.\n"],"names":[],"mappings":";;AAwBa,MAAA,sBAAA,GAAyB,CACpC,IACiD,KAAA;AACjD,EAAA,OAAO,CAAC,KAAO,EAAA,YAAY,EAAE,QAAS,CAAA,IAAA,EAAM,YAAY,EAAE,CAAA,CAAA;AAC5D;;;;"}
@@ -0,0 +1,137 @@
1
+ 'use strict';
2
+
3
+ var elasticsearch = require('@elastic/elasticsearch');
4
+ var opensearch = require('@opensearch-project/opensearch');
5
+ var ElasticSearchClientOptions = require('./ElasticSearchClientOptions.cjs.js');
6
+
7
+ class ElasticSearchClientWrapper {
8
+ elasticSearchClient;
9
+ openSearchClient;
10
+ constructor(options) {
11
+ this.openSearchClient = options.openSearchClient;
12
+ this.elasticSearchClient = options.elasticSearchClient;
13
+ }
14
+ static fromClientOptions(options) {
15
+ if (ElasticSearchClientOptions.isOpenSearchCompatible(options)) {
16
+ return new ElasticSearchClientWrapper({
17
+ openSearchClient: new opensearch.Client(options)
18
+ });
19
+ }
20
+ return new ElasticSearchClientWrapper({
21
+ elasticSearchClient: new elasticsearch.Client(options)
22
+ });
23
+ }
24
+ search(options) {
25
+ const searchOptions = {
26
+ ignore_unavailable: true,
27
+ allow_no_indices: true
28
+ };
29
+ if (this.openSearchClient) {
30
+ return this.openSearchClient.search({
31
+ ...options,
32
+ ...searchOptions
33
+ });
34
+ }
35
+ if (this.elasticSearchClient) {
36
+ return this.elasticSearchClient.search({
37
+ ...options,
38
+ ...searchOptions
39
+ });
40
+ }
41
+ throw new Error("No client defined");
42
+ }
43
+ bulk(bulkOptions) {
44
+ if (this.openSearchClient) {
45
+ return this.openSearchClient.helpers.bulk(bulkOptions);
46
+ }
47
+ if (this.elasticSearchClient) {
48
+ return this.elasticSearchClient.helpers.bulk(bulkOptions);
49
+ }
50
+ throw new Error("No client defined");
51
+ }
52
+ putIndexTemplate(template) {
53
+ if (this.openSearchClient) {
54
+ return this.openSearchClient.indices.putIndexTemplate(template);
55
+ }
56
+ if (this.elasticSearchClient) {
57
+ return this.elasticSearchClient.indices.putIndexTemplate(template);
58
+ }
59
+ throw new Error("No client defined");
60
+ }
61
+ listIndices(options) {
62
+ if (this.openSearchClient) {
63
+ return this.openSearchClient.indices.get(options);
64
+ }
65
+ if (this.elasticSearchClient) {
66
+ return this.elasticSearchClient.indices.get(options);
67
+ }
68
+ throw new Error("No client defined");
69
+ }
70
+ indexExists(options) {
71
+ if (this.openSearchClient) {
72
+ return this.openSearchClient.indices.exists(options);
73
+ }
74
+ if (this.elasticSearchClient) {
75
+ return this.elasticSearchClient.indices.exists(options);
76
+ }
77
+ throw new Error("No client defined");
78
+ }
79
+ deleteIndex(options) {
80
+ if (this.openSearchClient) {
81
+ return this.openSearchClient.indices.delete(options);
82
+ }
83
+ if (this.elasticSearchClient) {
84
+ return this.elasticSearchClient.indices.delete(options);
85
+ }
86
+ throw new Error("No client defined");
87
+ }
88
+ /**
89
+ * @deprecated unused by the ElasticSearch Engine, will be removed in the future
90
+ */
91
+ getAliases(options) {
92
+ const { aliases } = options;
93
+ if (this.openSearchClient) {
94
+ return this.openSearchClient.cat.aliases({
95
+ format: "json",
96
+ name: aliases
97
+ });
98
+ }
99
+ if (this.elasticSearchClient) {
100
+ return this.elasticSearchClient.cat.aliases({
101
+ format: "json",
102
+ name: aliases
103
+ });
104
+ }
105
+ throw new Error("No client defined");
106
+ }
107
+ createIndex(options) {
108
+ if (this.openSearchClient) {
109
+ return this.openSearchClient.indices.create(options);
110
+ }
111
+ if (this.elasticSearchClient) {
112
+ return this.elasticSearchClient.indices.create(options);
113
+ }
114
+ throw new Error("No client defined");
115
+ }
116
+ updateAliases(options) {
117
+ const filteredActions = options.actions.filter(Boolean);
118
+ if (this.openSearchClient) {
119
+ return this.openSearchClient.indices.updateAliases({
120
+ body: {
121
+ actions: filteredActions
122
+ }
123
+ });
124
+ }
125
+ if (this.elasticSearchClient) {
126
+ return this.elasticSearchClient.indices.updateAliases({
127
+ body: {
128
+ actions: filteredActions
129
+ }
130
+ });
131
+ }
132
+ throw new Error("No client defined");
133
+ }
134
+ }
135
+
136
+ exports.ElasticSearchClientWrapper = ElasticSearchClientWrapper;
137
+ //# sourceMappingURL=ElasticSearchClientWrapper.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ElasticSearchClientWrapper.cjs.js","sources":["../../src/engines/ElasticSearchClientWrapper.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Client as ElasticSearchClient } from '@elastic/elasticsearch';\nimport { Client as OpenSearchClient } from '@opensearch-project/opensearch';\nimport { Readable } from 'stream';\nimport {\n ElasticSearchClientOptions,\n isOpenSearchCompatible,\n} from './ElasticSearchClientOptions';\nimport { ElasticSearchCustomIndexTemplate } from './types';\n\n/**\n * @public\n */\nexport type ElasticSearchAliasAction =\n | {\n remove: { index: any; alias: any };\n add?: undefined;\n }\n | {\n add: { indices: any; alias: any; index?: undefined };\n remove?: undefined;\n }\n | {\n add: { index: any; alias: any; indices?: undefined };\n remove?: undefined;\n }\n | undefined;\n\n/**\n * @public\n */\nexport type ElasticSearchIndexAction = {\n index: {\n _index: string;\n [key: string]: any;\n };\n};\n\n/**\n * A wrapper class that exposes logical methods that are conditionally fired\n * against either a configured Elasticsearch client or a configured Opensearch\n * client.\n *\n * This is necessary because, despite its intention to be API-compatible, the\n * opensearch client does not support API key-based authentication. This is\n * also the sanest way to accomplish this while making typescript happy.\n *\n * In the future, if the differences between implementations become\n * unmaintainably divergent, we should split out the Opensearch and\n * Elasticsearch search engine implementations.\n *\n * @public\n */\nexport class ElasticSearchClientWrapper {\n private readonly elasticSearchClient: ElasticSearchClient | undefined;\n private readonly openSearchClient: OpenSearchClient | undefined;\n\n private constructor(options: {\n openSearchClient?: OpenSearchClient;\n elasticSearchClient?: ElasticSearchClient;\n }) {\n this.openSearchClient = options.openSearchClient;\n this.elasticSearchClient = options.elasticSearchClient;\n }\n\n static fromClientOptions(options: ElasticSearchClientOptions) {\n if (isOpenSearchCompatible(options)) {\n return new ElasticSearchClientWrapper({\n openSearchClient: new OpenSearchClient(options),\n });\n }\n\n return new ElasticSearchClientWrapper({\n elasticSearchClient: new ElasticSearchClient(options),\n });\n }\n\n search(options: { index: string | string[]; body: Object }) {\n const searchOptions = {\n ignore_unavailable: true,\n allow_no_indices: true,\n };\n\n if (this.openSearchClient) {\n return this.openSearchClient.search({\n ...options,\n ...searchOptions,\n });\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.search({\n ...options,\n ...searchOptions,\n });\n }\n\n throw new Error('No client defined');\n }\n\n bulk(bulkOptions: {\n datasource: Readable;\n onDocument: () => ElasticSearchIndexAction;\n refreshOnCompletion?: string | boolean;\n }) {\n if (this.openSearchClient) {\n return this.openSearchClient.helpers.bulk(bulkOptions);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.helpers.bulk(bulkOptions);\n }\n\n throw new Error('No client defined');\n }\n\n putIndexTemplate(template: ElasticSearchCustomIndexTemplate) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.putIndexTemplate(template);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.putIndexTemplate(template);\n }\n\n throw new Error('No client defined');\n }\n\n listIndices(options: { index: string }) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.get(options);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.get(options);\n }\n\n throw new Error('No client defined');\n }\n\n indexExists(options: { index: string | string[] }) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.exists(options);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.exists(options);\n }\n\n throw new Error('No client defined');\n }\n\n deleteIndex(options: { index: string | string[] }) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.delete(options);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.delete(options);\n }\n\n throw new Error('No client defined');\n }\n\n /**\n * @deprecated unused by the ElasticSearch Engine, will be removed in the future\n */\n getAliases(options: { aliases: string[] }) {\n const { aliases } = options;\n\n if (this.openSearchClient) {\n return this.openSearchClient.cat.aliases({\n format: 'json',\n name: aliases,\n });\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.cat.aliases({\n format: 'json',\n name: aliases,\n });\n }\n\n throw new Error('No client defined');\n }\n\n createIndex(options: { index: string }) {\n if (this.openSearchClient) {\n return this.openSearchClient.indices.create(options);\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.create(options);\n }\n\n throw new Error('No client defined');\n }\n\n updateAliases(options: { actions: ElasticSearchAliasAction[] }) {\n const filteredActions = options.actions.filter(Boolean);\n\n if (this.openSearchClient) {\n return this.openSearchClient.indices.updateAliases({\n body: {\n actions: filteredActions,\n },\n });\n }\n\n if (this.elasticSearchClient) {\n return this.elasticSearchClient.indices.updateAliases({\n body: {\n actions: filteredActions,\n },\n });\n }\n\n throw new Error('No client defined');\n }\n}\n"],"names":["isOpenSearchCompatible","OpenSearchClient","ElasticSearchClient"],"mappings":";;;;;;AAoEO,MAAM,0BAA2B,CAAA;AAAA,EACrB,mBAAA,CAAA;AAAA,EACA,gBAAA,CAAA;AAAA,EAET,YAAY,OAGjB,EAAA;AACD,IAAA,IAAA,CAAK,mBAAmB,OAAQ,CAAA,gBAAA,CAAA;AAChC,IAAA,IAAA,CAAK,sBAAsB,OAAQ,CAAA,mBAAA,CAAA;AAAA,GACrC;AAAA,EAEA,OAAO,kBAAkB,OAAqC,EAAA;AAC5D,IAAI,IAAAA,iDAAA,CAAuB,OAAO,CAAG,EAAA;AACnC,MAAA,OAAO,IAAI,0BAA2B,CAAA;AAAA,QACpC,gBAAA,EAAkB,IAAIC,iBAAA,CAAiB,OAAO,CAAA;AAAA,OAC/C,CAAA,CAAA;AAAA,KACH;AAEA,IAAA,OAAO,IAAI,0BAA2B,CAAA;AAAA,MACpC,mBAAA,EAAqB,IAAIC,oBAAA,CAAoB,OAAO,CAAA;AAAA,KACrD,CAAA,CAAA;AAAA,GACH;AAAA,EAEA,OAAO,OAAqD,EAAA;AAC1D,IAAA,MAAM,aAAgB,GAAA;AAAA,MACpB,kBAAoB,EAAA,IAAA;AAAA,MACpB,gBAAkB,EAAA,IAAA;AAAA,KACpB,CAAA;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