Clarify type generics in docs
Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
@@ -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<ElasticClient>(options => {
|
||||
if (!isOpenSearchCompatible(options)) {
|
||||
return new ElasticClient(options);
|
||||
}
|
||||
|
||||
throw new Error('Incompatible options');
|
||||
});
|
||||
|
||||
// Return an OpenSearch client
|
||||
const osClient = searchEngine.newClient<OpenSearchClient>(options => {
|
||||
if (isOpenSearchCompatible(options)) {
|
||||
return new OpenSearchClient(options);
|
||||
}
|
||||
|
||||
throw new Error('Incompatible options');
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user