From 2dbc917ccf47ad5e6ca634f2cd3f3c65c7ecc63a Mon Sep 17 00:00:00 2001 From: Thomas Cardonne Date: Wed, 8 May 2024 12:30:16 +0200 Subject: [PATCH] fix: deprecate getAliases instead of removing it Signed-off-by: Thomas Cardonne --- .../api-report.md | 6 +++ .../ElasticSearchClientWrapper.test.ts | 38 +++++++++++++++++++ .../src/engines/ElasticSearchClientWrapper.ts | 23 +++++++++++ 3 files changed, 67 insertions(+) diff --git a/plugins/search-backend-module-elasticsearch/api-report.md b/plugins/search-backend-module-elasticsearch/api-report.md index 2c23c82f76347..4c55dad91e14e 100644 --- a/plugins/search-backend-module-elasticsearch/api-report.md +++ b/plugins/search-backend-module-elasticsearch/api-report.md @@ -153,6 +153,12 @@ export class ElasticSearchClientWrapper { static fromClientOptions( options: ElasticSearchClientOptions, ): ElasticSearchClientWrapper; + // @deprecated (undocumented) + getAliases(options: { + aliases: string[]; + }): + | TransportRequestPromise, unknown>> + | TransportRequestPromise_2, unknown>>; // (undocumented) indexExists(options: { index: string | string[]; diff --git a/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchClientWrapper.test.ts b/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchClientWrapper.test.ts index e888aa4506981..dd5a37e5f0628 100644 --- a/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchClientWrapper.test.ts +++ b/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchClientWrapper.test.ts @@ -28,6 +28,11 @@ jest.mock('@elastic/elasticsearch', () => ({ search: jest .fn() .mockImplementation(async args => ({ client: 'es', args })), + cat: { + aliases: jest + .fn() + .mockImplementation(async args => ({ client: 'es', args })), + }, helpers: { bulk: jest .fn() @@ -60,6 +65,11 @@ jest.mock('@opensearch-project/opensearch', () => ({ search: jest .fn() .mockImplementation(async args => ({ client: 'os', args })), + cat: { + aliases: jest + .fn() + .mockImplementation(async args => ({ client: 'os', args })), + }, helpers: { bulk: jest .fn() @@ -189,6 +199,20 @@ describe('ElasticSearchClientWrapper', () => { expect(result.args).toStrictEqual(input); }); + it('getAliases', async () => { + const wrapper = ElasticSearchClientWrapper.fromClientOptions(esOptions); + + const input = { aliases: ['xyz'] }; + const result = (await wrapper.getAliases(input)) as any; + + // Should call the OpenSearch client with expected input. + expect(result.client).toBe('es'); + expect(result.args).toStrictEqual({ + format: 'json', + name: input.aliases, + }); + }); + it('updateAliases', async () => { const wrapper = ElasticSearchClientWrapper.fromClientOptions(esOptions); @@ -313,6 +337,20 @@ describe('ElasticSearchClientWrapper', () => { expect(result.args).toStrictEqual(input); }); + it('getAliases', async () => { + const wrapper = ElasticSearchClientWrapper.fromClientOptions(osOptions); + + const input = { aliases: ['xyz'] }; + const result = (await wrapper.getAliases(input)) as any; + + // Should call the OpenSearch client with expected input. + expect(result.client).toBe('os'); + expect(result.args).toStrictEqual({ + format: 'json', + name: input.aliases, + }); + }); + it('updateAliases', async () => { const wrapper = ElasticSearchClientWrapper.fromClientOptions(osOptions); diff --git a/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchClientWrapper.ts b/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchClientWrapper.ts index 454e1a6d507c9..4bf8a3d998239 100644 --- a/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchClientWrapper.ts +++ b/plugins/search-backend-module-elasticsearch/src/engines/ElasticSearchClientWrapper.ts @@ -177,6 +177,29 @@ export class ElasticSearchClientWrapper { throw new Error('No client defined'); } + /** + * @deprecated unused by the ElasticSearch Engine, will be removed in the future + */ + getAliases(options: { aliases: string[] }) { + const { aliases } = options; + + if (this.openSearchClient) { + return this.openSearchClient.cat.aliases({ + format: 'json', + name: aliases, + }); + } + + if (this.elasticSearchClient) { + return this.elasticSearchClient.cat.aliases({ + format: 'json', + name: aliases, + }); + } + + throw new Error('No client defined'); + } + createIndex(options: { index: string }) { if (this.openSearchClient) { return this.openSearchClient.indices.create(options);