|
|
@@ -23,35 +23,20 @@ import {
|
|
|
} from './elasticsearch-client-types';
|
|
|
|
|
|
|
|
|
-type ESClientOptions = ES7ClientOptions | ES8ClientOptions;
|
|
|
-
|
|
|
-// Type guard for ES7ClientOptions
|
|
|
-const isES7Options = (options: any): options is ES7ClientOptions => {
|
|
|
- return options.ssl != null;
|
|
|
-};
|
|
|
+type ElasticsearchClientParams =
|
|
|
+ | [ isES7: true, options: ES7ClientOptions, rejectUnauthorized: boolean ]
|
|
|
+ | [ isES7: false, options: ES8ClientOptions, rejectUnauthorized: boolean ]
|
|
|
|
|
|
export default class ElasticsearchClient {
|
|
|
|
|
|
- client: ES7Client | ES8Client;
|
|
|
-
|
|
|
- constructor(isES7: boolean, options: ES7ClientOptions, rejectUnauthorized: boolean)
|
|
|
-
|
|
|
- constructor(isES7: boolean, options: ES8ClientOptions, rejectUnauthorized: boolean)
|
|
|
-
|
|
|
- constructor(isES7: boolean, options: ESClientOptions, rejectUnauthorized = false) {
|
|
|
-
|
|
|
- const encryptionOption = isES7
|
|
|
- ? { ssl: { rejectUnauthorized } }
|
|
|
- : { tls: { rejectUnauthorized } };
|
|
|
+ private client: ES7Client | ES8Client;
|
|
|
|
|
|
- const esOptions: ESClientOptions = { ...options, ...encryptionOption };
|
|
|
+ constructor(...params: ElasticsearchClientParams) {
|
|
|
+ const [isES7, options, rejectUnauthorized] = params;
|
|
|
|
|
|
- if (isES7Options(esOptions)) {
|
|
|
- this.client = new ES7Client(esOptions);
|
|
|
- }
|
|
|
- else {
|
|
|
- this.client = new ES8Client(esOptions);
|
|
|
- }
|
|
|
+ this.client = isES7
|
|
|
+ ? new ES7Client({ ...options, ssl: { rejectUnauthorized } })
|
|
|
+ : new ES8Client({ ...options, tls: { rejectUnauthorized } });
|
|
|
}
|
|
|
|
|
|
async bulk(params: ES7RequestParams.Bulk & estypes.BulkRequest): Promise<BulkResponse | estypes.BulkResponse> {
|