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

fix: GET /_api/v3/search/indices

Shun Miyazawa 2 лет назад
Родитель
Сommit
a3910c5897
1 измененных файлов с 13 добавлено и 5 удалено
  1. 13 5
      apps/app/src/server/service/search-delegator/elasticsearch.ts

+ 13 - 5
apps/app/src/server/service/search-delegator/elasticsearch.ts

@@ -232,8 +232,11 @@ class ElasticsearchDelegator implements SearchDelegator<Data, ESTermsKey, ESQuer
     const tmpIndexName = `${indexName}-tmp`;
 
     // check existence
-    const { body: isExistsMainIndex } = await client.indices.exists({ index: indexName });
-    const { body: isExistsTmpIndex } = await client.indices.exists({ index: tmpIndexName });
+    const isExistsMainIndexResult = await client.indices.exists({ index: indexName });
+    const isExistsMainIndex = this.isElasticsearchV7 ? isExistsMainIndexResult.body : isExistsMainIndexResult;
+
+    const isExistsTmpIndexResult = await client.indices.exists({ index: tmpIndexName });
+    const isExistsTmpIndex = this.isElasticsearchV7 ? isExistsTmpIndexResult.body : isExistsTmpIndexResult;
 
     // create indices name list
     const existingIndices: string[] = [];
@@ -249,9 +252,13 @@ class ElasticsearchDelegator implements SearchDelegator<Data, ESTermsKey, ESQuer
       };
     }
 
-    const { body: indicesBody } = await client.indices.stats({ index: existingIndices, metric: ['docs', 'store', 'indexing'] });
-    const { indices } = indicesBody;
-    const { body: aliases } = await client.indices.getAlias({ index: existingIndices });
+    const indicesStatsResponse = await client.indices.stats({ index: existingIndices, metric: ['docs', 'store', 'indexing'] });
+    const indicesStats = this.isElasticsearchV7 ? indicesStatsResponse.body : indicesStatsResponse;
+    const { indices } = indicesStats;
+
+    const getAliasResponse = await client.indices.getAlias({ index: existingIndices });
+    const aliases = this.isElasticsearchV7 ? getAliasResponse.body : getAliasResponse;
+
 
     const isMainIndexHasAlias = isExistsMainIndex && aliases[indexName].aliases != null && aliases[indexName].aliases[aliasName] != null;
     const isTmpIndexHasAlias = isExistsTmpIndex && aliases[tmpIndexName].aliases != null && aliases[tmpIndexName].aliases[aliasName] != null;
@@ -263,6 +270,7 @@ class ElasticsearchDelegator implements SearchDelegator<Data, ESTermsKey, ESQuer
       aliases,
       isNormalized,
     };
+
   }
 
   /**