From 1db252e066dc84deec20e09580c302dd46b6067c Mon Sep 17 00:00:00 2001 From: Chang Liu Date: Mon, 6 Mar 2023 14:16:43 -0800 Subject: [PATCH] Replace legacy template with index template (#1359) Signed-off-by: Chang Liu (cherry picked from commit b69a364ebb70e19dedb4dbf21b1764b47a49f250) --- server/multitenancy/tenant_index.ts | 14 ++++++++------ server/multitenancy/test/tenant_index.test.ts | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/server/multitenancy/tenant_index.ts b/server/multitenancy/tenant_index.ts index 739de26..a9de653 100644 --- a/server/multitenancy/tenant_index.ts +++ b/server/multitenancy/tenant_index.ts @@ -39,11 +39,11 @@ export async function setupIndexTemplate( ) { const mappings: IndexMapping = buildActiveMappings(mergeTypes(typeRegistry.getAllTypes())); try { - await esClient.indices.putTemplate({ + await esClient.indices.putIndexTemplate({ name: 'tenant_template', body: { - // Setting order to the max value to avoid being overridden by custom templates. - order: MAX_INTEGER, + // Setting priority to the max value to avoid being overridden by custom index templates. + priority: MAX_INTEGER, index_patterns: [ opensearchDashboardsIndex + '_-*_*', opensearchDashboardsIndex + '_0*_*', @@ -57,10 +57,12 @@ export async function setupIndexTemplate( opensearchDashboardsIndex + '_8*_*', opensearchDashboardsIndex + '_9*_*', ], - settings: { - number_of_shards: 1, + template: { + settings: { + number_of_shards: 1, + }, + mappings, }, - mappings, }, }); } catch (error) { diff --git a/server/multitenancy/test/tenant_index.test.ts b/server/multitenancy/test/tenant_index.test.ts index cc295f7..0ef5176 100644 --- a/server/multitenancy/test/tenant_index.test.ts +++ b/server/multitenancy/test/tenant_index.test.ts @@ -18,26 +18,27 @@ import { MAX_INTEGER } from '../../../common'; describe('Tenant index template', () => { const mockOpenSearchClient = { indices: { - putTemplate: jest.fn().mockImplementation((template) => { + putIndexTemplate: jest.fn().mockImplementation((template) => { return template; }), }, }; - const order = MAX_INTEGER; + const priority = MAX_INTEGER; - it('put template', () => { - const result = mockOpenSearchClient.indices.putTemplate({ + it('put index template', () => { + const result = mockOpenSearchClient.indices.putIndexTemplate({ name: 'test_index_template_a', body: { - order, + priority, index_patterns: 'test_index_patterns_a', - mappings: { - dynamic: 'strict', - properties: { baz: { type: 'text' } }, + template: { + settings: { + number_of_shards: 1, + }, }, }, }); - expect(result.body.order).toEqual(order); + expect(result.body.priority).toEqual(priority); }); });