Skip to main content

ElasticSearchSearchEngine.newClient()

Home > @backstage/plugin-search-backend-module-elasticsearch > ElasticSearchSearchEngine > newClient

Create a custom search client from the derived search client configuration. This need not be the same client that the engine uses internally.

Signature:

newClient<T>(create: (options: ElasticSearchClientOptions) => T): T;

Parameters

ParameterTypeDescription
create(options: ElasticSearchClientOptions) => T

Returns:

T

Example

Instantiate an instance of an Elasticsearch client.

import { isOpenSearchCompatible } from '@backstage/plugin-search-backend-module-elasticsearch';
import { Client } from '@elastic/elasticsearch';

const client = searchEngine.newClient<Client>(options => {
// This type guard ensures options are compatible with either OpenSearch
// or Elasticsearch client constructors.
if (!isOpenSearchCompatible(options)) {
return new Client(options);
}
throw new Error('Incompatible options provided');
});