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

- Use eslint-disable camelcase for file on elasticsearch-client-types.ts
- Add type IndicesExistsResponse
- Add type ValidateQueryResponse
- Add type ClusterHealthResponse
- Add and adjust cluster.health on elasticsearch-client.ts
- Add and adjust indices.exists on elasticsearch-client.ts
- Add and adjust indices.validateQuery on elasticsearch-client.ts

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

+ 31 - 2
packages/app/src/server/service/search-delegator/elasticsearch-client-types.ts

@@ -1,3 +1,4 @@
+/* eslint-disable camelcase */
 export type NodesInfoResponse = {
   nodes: Record<
     string,
@@ -12,6 +13,8 @@ export type CatIndicesResponse = {
   index: string
 }[]
 
+export type IndicesExistsResponse = boolean
+
 export type IndicesExistsAliasResponse = boolean
 
 export type CatAliasesResponse = {
@@ -28,7 +31,6 @@ export type BulkResponse = {
 
 export type SearchResponse = {
   took: number
-  // eslint-disable-next-line camelcase
   timed_out: boolean
   _shards: {
     total: number
@@ -41,7 +43,6 @@ export type SearchResponse = {
       value: number
       relation: string
     } // 6.x.x | 7.x.x
-    // eslint-disable-next-line camelcase
     max_score: number | null
     hits: Record<string, {
       _index: string
@@ -52,3 +53,31 @@ export type SearchResponse = {
     }>[]
   }
 }
+
+export type ValidateQueryResponse = {
+  valid: boolean,
+  _shards: {
+    total: number,
+    successful: number,
+    failed: number
+  },
+  explanations: Record<string, any>[]
+}
+
+export type ClusterHealthResponse = {
+  cluster_name: string,
+  status: string,
+  timed_out: boolean,
+  number_of_nodes: number,
+  number_of_data_nodes: number,
+  active_primary_shards: number,
+  active_shards: number,
+  relocating_shards: number,
+  initializing_shards: number,
+  unassigned_shards: number,
+  delayed_unassigned_shards: number,
+  number_of_pending_tasks: number,
+  number_of_in_flight_fetch: number,
+  task_max_waiting_in_queue_millis: number,
+  active_shards_percent_as_number: number
+}

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

@@ -6,9 +6,12 @@ import {
   BulkResponse,
   CatAliasesResponse,
   CatIndicesResponse,
+  IndicesExistsResponse,
   IndicesExistsAliasResponse,
   NodesInfoResponse,
   SearchResponse,
+  ValidateQueryResponse,
+  ClusterHealthResponse,
 } from './elasticsearch-client-types';
 
 type ApiResponse<T = any, C = any> = ES6ApiResponse<T, C> | ES7ApiResponse<T, C>
@@ -33,17 +36,26 @@ export default class ElasticsearchClient {
       this.client instanceof ES6Client ? this.client.cat.indices(params) : this.client.cat.indices(params),
   }
 
+  cluster = {
+    health: (params: ES6RequestParams.ClusterHealth & ES7RequestParams.ClusterHealth): Promise<ApiResponse<ClusterHealthResponse>> =>
+      this.client instanceof ES6Client ? this.client.cluster.health(params) : this.client.cluster.health(params),
+  }
+
   indices = {
     create: (params: ES6RequestParams.IndicesCreate & ES7RequestParams.IndicesCreate) =>
       this.client instanceof ES6Client ? this.client.indices.create(params) : this.client.indices.create(params),
     delete: (params: ES6RequestParams.IndicesDelete & ES7RequestParams.IndicesDelete) =>
       this.client instanceof ES6Client ? this.client.indices.delete(params) : this.client.indices.delete(params),
+    exists: (params: ES6RequestParams.IndicesExists & ES7RequestParams.IndicesExists): Promise<ApiResponse<IndicesExistsResponse>> =>
+      this.client instanceof ES6Client ? this.client.indices.exists(params) : this.client.indices.exists(params),
     existsAlias: (params: ES6RequestParams.IndicesExistsAlias & ES7RequestParams.IndicesExistsAlias): Promise<ApiResponse<IndicesExistsAliasResponse>> =>
       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),
     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),
   }
 
   nodes = {

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

@@ -615,7 +615,6 @@ class ElasticsearchDelegator implements SearchDelegator<Data> {
       logger.debug('ES returns explanations: ', result.explanations);
     }
 
-    const { body } = await this.client.search(query);
     const { body: result } = await this.client.search(query);
 
     // for debug