Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});