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
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const createMockEsClient = () => {
template: { mappings: {} },
}),
putMapping: jest.fn().mockResolvedValue({}),
putSettings: jest.fn().mockResolvedValue({}),
},
} as unknown as jest.Mocked<ElasticsearchClient>;
return client;
Expand Down Expand Up @@ -162,6 +163,24 @@ describe('StorageIndexAdapter - transport options forwarding', () => {
);
});

it('includes settings in the index template', async () => {
const adapter = new StorageIndexAdapter(esClient, loggerMock, storageSettings);
const client = adapter.getClient();

await client.index({ id: 'doc1', document: { foo: 'bar' } });

expect(esClient.indices.putIndexTemplate).toHaveBeenCalledWith(
expect.objectContaining({
template: expect.objectContaining({
settings: expect.objectContaining({
auto_expand_replicas: '0-1',
number_of_shards: 1,
}),
}),
})
);
});

it('works without transport options (backward compatible)', async () => {
const adapter = new StorageIndexAdapter(esClient, loggerMock, storageSettings);
const client = adapter.getClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ export class StorageIndexAdapter<
const version = getSchemaVersion(this.storage);

const template: IndicesPutIndexTemplateIndexTemplateMapping = {
settings: {
auto_expand_replicas: '0-1',
number_of_shards: 1,
},
mappings: {
_meta: {
version,
Expand Down Expand Up @@ -319,11 +323,13 @@ export class StorageIndexAdapter<
if (!writeIndex) {
this.logger.debug(`Creating index`);
await this.createIndex();
} else if (writeIndex?.state.mappings?._meta?.version !== expectedSchemaVersion) {
this.logger.debug(`Updating mappings of existing index due to schema version mismatch`);
await this.updateMappingsOfExistingIndex({
name: writeIndex.name,
});
} else {
if (writeIndex.state.mappings?._meta?.version !== expectedSchemaVersion) {
this.logger.debug(`Updating mappings of existing index due to schema version mismatch`);
await this.updateMappingsOfExistingIndex({
name: writeIndex.name,
});
}
}

return await cb();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,10 @@ describe('StorageIndexAdapter', () => {
is_write_index: true,
},
});

expect(getIndexResponse[writeIndexName].settings?.index?.auto_expand_replicas).toEqual('0-1');

expect(getIndexResponse[writeIndexName].settings?.index?.number_of_shards).toEqual('1');
}

async function verifyClean() {
Expand Down
Loading