Merge pull request #28697 from RoadieHQ/enable-index-prefix-configuration

enable configuration of indexPrefix
This commit is contained in:
Andre Wanlin
2025-02-20 06:59:26 -06:00
committed by GitHub
5 changed files with 37 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-search-backend-module-elasticsearch': patch
---
Allow `indexPrefix` configuration through the `app-config.yaml`
+17
View File
@@ -238,3 +238,20 @@ search:
```
> You can also increase the batch size if you are using a large ES instance.
### Elasticsearch Index Name Customization
By default, the Elasticsearch indexer creates index names based on their type, a separator, and the current date as a postfix. You can configure a custom prefix for all indices by adding the following section to your app configuration.
An example of a default index name would look like this:
`software-catalog-index__20250219`
To prefix all indices with a custom string (e.g., `custom-prefix`), use the following configuration:
```yaml
search:
elasticsearch:
indexPrefix: custom-prefix-
```
After applying this setting, an index name would look like this: `custom-prefix-software-catalog-index__20250219`
@@ -21,6 +21,10 @@ export interface Config {
* Options for ElasticSearch
*/
elasticsearch?: {
/**
* Prefix to be used for all index creation. Value will be put in front of the index as is.
*/
indexPrefix?: string;
/**
* Batch size for elastic search indexing tasks. Defaults to 1000.
*/
@@ -140,7 +140,7 @@ export class ElasticSearchSearchEngineIndexer extends BatchSearchEngineIndexer {
// does not occur, and clean up the empty index we just created.
if (this.processed === 0) {
this.logger.warn(
`Index for ${this.type} was not ${
`Index for ${this.indexName} of ${this.type} was not ${
this.removableIndices.length ? 'replaced' : 'created'
}: indexer received 0 documents`,
);
@@ -158,9 +158,9 @@ export class ElasticSearchSearchEngineIndexer extends BatchSearchEngineIndexer {
// stale indices can be referenced for deletion in case initial attempt
// fails. Allow errors to bubble up so that we can clean up the created index.
this.logger.info(
`Indexing completed for index ${this.type} in ${duration(
this.startTimestamp,
)}`,
`Indexing completed for index ${this.indexName} of ${
this.type
} in ${duration(this.startTimestamp)}`,
result,
);
await this.elasticSearchClientWrapper.updateAliases({
@@ -76,12 +76,18 @@ export default createBackendModule({
);
return;
}
const indexPrefix = config.getOptionalString(
'search.elasticsearch.indexPrefix',
);
if (indexPrefix) {
logger.info(`Index prefix will be used for indices: ${indexPrefix}`);
}
searchEngineRegistry.setSearchEngine(
await ElasticSearchSearchEngine.fromConfig({
logger,
config,
translator,
indexPrefix,
}),
);
},