Просмотр исходного кода

- Implement typescript type from researched API response
- Add type IndicesStatsResponse
- Add type ReindexResponse
- Add type IndicesGetAliasResponse
- Add and adjust indices.stats on elasticsearch-client.ts
- Add and adjust reindex on elasticsearch-client.ts
- Add and adjust indices.getAlias on elasticsearch-client.ts
** for IndicesStatsResponse._all.* and IndicesStatsResponse.indices I use any
** for client.indices.getAlias I didn't add promise because the result is relative

LuqmanHakim-Grune 4 лет назад
Родитель
Сommit
3c2ad8edff

+ 30 - 0
packages/app/src/server/service/search-delegator/elasticsearch-client-types.ts

@@ -81,3 +81,33 @@ export type ClusterHealthResponse = {
   task_max_waiting_in_queue_millis: number,
   active_shards_percent_as_number: number
 }
+
+export type IndicesStatsResponse = {
+  _shards: {
+    total: number,
+    successful: number,
+    failed: number
+  },
+  _all: {
+    primaries: any,
+    total: any
+  },
+  indices: any
+}
+
+export type ReindexResponse = {
+  took: number,
+  timed_out: boolean,
+  total: number,
+  updated: number,
+  created: number,
+  deleted: number,
+  batches: number,
+  noops: number,
+  version_conflicts: number,
+  retries: number,
+  throttled_millis: number,
+  requests_per_second: number,
+  throttled_until_millis: number,
+  failures: any | null
+}

+ 10 - 0
packages/app/src/server/service/search-delegator/elasticsearch-client.ts

@@ -12,6 +12,8 @@ import {
   SearchResponse,
   ValidateQueryResponse,
   ClusterHealthResponse,
+  IndicesStatsResponse,
+  ReindexResponse,
 } from './elasticsearch-client-types';
 
 type ApiResponse<T = any, C = any> = ES6ApiResponse<T, C> | ES7ApiResponse<T, C>
@@ -52,10 +54,14 @@ export default class ElasticsearchClient {
       this.client instanceof ES6Client ? this.client.indices.existsAlias(params) : this.client.indices.existsAlias(params),
     putAlias: (params: ES6RequestParams.IndicesPutAlias & ES7RequestParams.IndicesPutAlias) =>
       this.client instanceof ES6Client ? this.client.indices.putAlias(params) : this.client.indices.putAlias(params),
+    getAlias: (params: ES6RequestParams.IndicesGetAlias & ES7RequestParams.IndicesGetAlias) =>
+      this.client instanceof ES6Client ? this.client.indices.getAlias(params) : this.client.indices.getAlias(params),
     updateAliases: (params: ES6RequestParams.IndicesUpdateAliases & ES7RequestParams.IndicesUpdateAliases) =>
       this.client instanceof ES6Client ? this.client.indices.updateAliases(params) : this.client.indices.updateAliases(params),
     validateQuery: (params: ES6RequestParams.IndicesValidateQuery & ES7RequestParams.IndicesValidateQuery): Promise<ApiResponse<ValidateQueryResponse>> =>
       this.client instanceof ES6Client ? this.client.indices.validateQuery(params) : this.client.indices.validateQuery(params),
+    stats: (params: ES6RequestParams.IndicesStats & ES7RequestParams.IndicesStats): Promise<ApiResponse<IndicesStatsResponse>> =>
+      this.client instanceof ES6Client ? this.client.indices.stats(params) : this.client.indices.stats(params),
   }
 
   nodes = {
@@ -66,6 +72,10 @@ export default class ElasticsearchClient {
     return this.client instanceof ES6Client ? this.client.ping() : this.client.ping();
   }
 
+  reindex(params: ES6RequestParams.Reindex & ES7RequestParams.Reindex): Promise<ApiResponse<ReindexResponse>> {
+    return this.client instanceof ES6Client ? this.client.reindex(params) : this.client.reindex(params);
+  }
+
   search(params: ES6RequestParams.Search & ES7RequestParams.Search): Promise<ApiResponse<SearchResponse>> {
     return this.client instanceof ES6Client ? this.client.search(params) : this.client.search(params);
   }