From 60834500699fc2e4b205fea3e75d5ef7e2ed3372 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 22 Mar 2023 17:30:42 -0500 Subject: [PATCH] Replace legacy template with index template (#1359) (#1363) Signed-off-by: Chang Liu (cherry picked from commit b69a364ebb70e19dedb4dbf21b1764b47a49f250) Co-authored-by: Chang Liu --- 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 739de26b0..a9de653db 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 cc295f787..0ef517661 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); }); });