async createOrUpdateMappings()

in src/searchMappingsManager/index.ts [58:89]


    async createOrUpdateMappings() {
        const resourceTypesWithErrors = [];
        for (const [resourceType, mappings] of Object.entries(this.searchMappings)) {
            try {
                if (!(await this.indexExists(resourceType))) {
                    console.log(`index for ${resourceType} was not found. It will be created`);
                    await this.createIndexWithMapping(resourceType, mappings);
                } else {
                    try {
                        await this.updateMapping(resourceType, mappings);
                    } catch (e) {
                        if (this.ignoreMappingsErrorsForExistingIndices) {
                            console.log(
                                `Warning: Failed to update mappings for ${resourceType}`,
                                JSON.stringify(e, null, 2),
                            );
                        } else {
                            throw e;
                        }
                    }
                }
            } catch (e) {
                console.log(e);
                console.log(`Failed to update mapping for ${resourceType}:`, JSON.stringify(e, null, 2));
                resourceTypesWithErrors.push(resourceType);
            }
        }

        if (resourceTypesWithErrors.length > 0) {
            throw new Error(`Failed to update mappings for: ${resourceTypesWithErrors}`);
        }
    }