Skip to content

Commit

Permalink
Replace legacy template with index template (#1359)
Browse files Browse the repository at this point in the history
Signed-off-by: Chang Liu <[email protected]>
(cherry picked from commit b69a364)
  • Loading branch information
cliu123 authored and github-actions[bot] committed Mar 6, 2023
1 parent c4791f8 commit fd3fd47
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
14 changes: 8 additions & 6 deletions server/multitenancy/tenant_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*_*',
Expand All @@ -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) {
Expand Down
19 changes: 10 additions & 9 deletions server/multitenancy/test/tenant_index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit fd3fd47

Please sign in to comment.