add possibilities to pass options to elasticSearchEngineModule
Signed-off-by: Emma Indal <emma.indahl@gmail.com>
This commit is contained in:
@@ -22,8 +22,8 @@ import { todoPlugin } from '@backstage/plugin-todo-backend';
|
||||
import { techdocsPlugin } from '@backstage/plugin-techdocs-backend/alpha';
|
||||
import { searchPlugin } from '@backstage/plugin-search-backend';
|
||||
import { elasticSearchEngineModule } from '@backstage/plugin-search-backend-module-elasticsearch';
|
||||
import { pgSearchEngineModule } from '@backstage/plugin-search-backend-module-pg';
|
||||
import { lunrSearchEngineModule } from '@backstage/plugin-search-backend-node/';
|
||||
// import { pgSearchEngineModule } from '@backstage/plugin-search-backend-module-pg';
|
||||
// import { lunrSearchEngineModule } from '@backstage/plugin-search-backend-node/';
|
||||
|
||||
const backend = createBackend();
|
||||
|
||||
@@ -34,8 +34,14 @@ backend.add(todoPlugin());
|
||||
backend.add(techdocsPlugin());
|
||||
|
||||
backend.add(searchPlugin());
|
||||
backend.add(elasticSearchEngineModule());
|
||||
backend.add(pgSearchEngineModule());
|
||||
backend.add(lunrSearchEngineModule());
|
||||
// just as example of search engine module, remove before shipping and use default
|
||||
backend.add(
|
||||
elasticSearchEngineModule({
|
||||
indexTemplate: {
|
||||
name: 'my-custom-template',
|
||||
body: { index_patterns: ['*index*'], template: {} },
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
backend.start();
|
||||
|
||||
+34
-19
@@ -530,24 +530,39 @@ export async function createElasticSearchClientOptions(
|
||||
};
|
||||
}
|
||||
|
||||
export const elasticSearchEngineModule = createBackendModule({
|
||||
moduleId: 'elasticSearchEngineModule',
|
||||
pluginId: 'search-backend',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
searchEngineRegistry: searchEngineRegistryExtensionPoint,
|
||||
logger: coreServices.logger,
|
||||
config: coreServices.config,
|
||||
},
|
||||
async init({ searchEngineRegistry, logger, config }) {
|
||||
searchEngineRegistry.setSearchEngine(
|
||||
await ElasticSearchSearchEngine.fromConfig({
|
||||
export type ElasticSearchEngineModuleOptions = {
|
||||
translator?: ElasticSearchQueryTranslator;
|
||||
indexTemplate?: ElasticSearchCustomIndexTemplate;
|
||||
};
|
||||
|
||||
export const elasticSearchEngineModule = createBackendModule(
|
||||
(options?: ElasticSearchEngineModuleOptions) => ({
|
||||
moduleId: 'elasticSearchEngineModule',
|
||||
pluginId: 'search-backend',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
searchEngineRegistry: searchEngineRegistryExtensionPoint,
|
||||
logger: coreServices.logger,
|
||||
config: coreServices.config,
|
||||
},
|
||||
async init({ searchEngineRegistry, logger, config }) {
|
||||
const searchEngine = await ElasticSearchSearchEngine.fromConfig({
|
||||
logger: loggerToWinstonLogger(logger),
|
||||
config: config,
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
||||
searchEngineRegistry.setSearchEngine(searchEngine);
|
||||
// set custom translator if available
|
||||
if (options?.translator) {
|
||||
searchEngine.setTranslator(options.translator);
|
||||
}
|
||||
|
||||
// set custom index template if available TODO(emmaindal): make it possible to pass in mutliple index templates
|
||||
if (options?.indexTemplate) {
|
||||
searchEngine.setIndexTemplate(options.indexTemplate);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user