Skip to content

Commit

Permalink
Updating index settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed Oct 14, 2022
1 parent 9360a4e commit 52ca188
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { defaultLifecyclePolicy } from '../../common/assets/lifecycle_policies/d
import type { IndexInfo } from './index_info';

const INSTALLATION_TIMEOUT = 20 * 60 * 1000; // 20 minutes

const TOTAL_FIELDS_LIMIT = 1900;
interface ConstructorOptions {
getResourceName(relativeName: string): string;
getClusterClient: () => Promise<ElasticsearchClient>;
Expand Down Expand Up @@ -169,10 +169,33 @@ export class ResourceInstaller {

// Find all concrete indices for all namespaces of the index.
const concreteIndices = await this.fetchConcreteIndices(aliases, backingIndices);
// Update total field limit setting of found indices
await Promise.all(concreteIndices.map((item) => this.updateTotalFieldLimitSetting(item)));
// Update mappings of the found indices.
await Promise.all(concreteIndices.map((item) => this.updateAliasWriteIndexMapping(item)));
}

private async updateTotalFieldLimitSetting({ index, alias }: ConcreteIndexInfo) {
const { logger, getClusterClient } = this.options;
const clusterClient = await getClusterClient();

try {
await clusterClient.indices.putSettings({
index,
body: {
// @ts-expect-error
'index.mapping.total_fields.limit': TOTAL_FIELDS_LIMIT,
},
});
return;
} catch (err) {
logger.error(
`Failed to PUT index.mapping.total_fields.limit settings for alias ${alias}: ${err.message}`
);
throw err;
}
}

// NOTE / IMPORTANT: Please note this will update the mappings of backing indices but
// *not* the settings. This is due to the fact settings can be classed as dynamic and static,
// and static updates will fail on an index that isn't closed. New settings *will* be applied as part
Expand Down Expand Up @@ -351,7 +374,7 @@ export class ResourceInstaller {
name: ilmPolicyName,
rollover_alias: primaryNamespacedAlias,
},
'index.mapping.total_fields.limit': 1900,
'index.mapping.total_fields.limit': TOTAL_FIELDS_LIMIT,
auto_expand_replicas: '0-1',
},
mappings: {
Expand Down

0 comments on commit 52ca188

Please sign in to comment.