diff --git a/docs/features/search/search-engines.md b/docs/features/search/search-engines.md index bb1b07f050..d06e401847 100644 --- a/docs/features/search/search-engines.md +++ b/docs/features/search/search-engines.md @@ -136,14 +136,22 @@ import { isOpenSearchCompatible } from '@backstage/plugin-search-backend-module- import { Client as ElasticClient } from '@elastic/elasticsearch'; import { Client as OpenSearchClient } from '@opensearch-project/opensearch'; -const client = searchEngine.newClient(options => { - // In reality, you would only import / instantiate one of the following, but - // for illustrative purposes, here are both: - if (isOpenSearchCompatible(options)) { - return new OpenSearchClient(options); - } else { +// Return an Elasticsearch client +const esClient = searchEngine.newClient(options => { + if (!isOpenSearchCompatible(options)) { return new ElasticClient(options); } + + throw new Error('Incompatible options'); +}); + +// Return an OpenSearch client +const osClient = searchEngine.newClient(options => { + if (isOpenSearchCompatible(options)) { + return new OpenSearchClient(options); + } + + throw new Error('Incompatible options'); }); ```