From 956d511a91a714a2f262595e35e8d8b8d9bdaadd Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Thu, 14 May 2020 12:06:53 +0200 Subject: [PATCH] Fix logic when calling get index endpoint with empty array Also remove unused translations --- .../server/lib/fetch_indices.ts | 21 ++++++++++++------- .../translations/translations/ja-JP.json | 1 - .../translations/translations/zh-CN.json | 1 - .../management/index_management/indices.js | 2 ++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/index_management/server/lib/fetch_indices.ts b/x-pack/plugins/index_management/server/lib/fetch_indices.ts index b965f8f2907d8..6c0d376922b62 100644 --- a/x-pack/plugins/index_management/server/lib/fetch_indices.ts +++ b/x-pack/plugins/index_management/server/lib/fetch_indices.ts @@ -38,9 +38,17 @@ async function fetchIndicesCall( callAsCurrentUser: CallAsCurrentUser, indexNames?: string[] ): Promise { + let indexNamesCSV: string; + if (indexNames && indexNames.length) { + indexNamesCSV = indexNames.join(','); + } else { + indexNamesCSV = '*'; + } + + // This call retrieves alias and settings (incl. hidden status) information about indices const indices: GetIndicesResponse = await callAsCurrentUser('transport.request', { method: 'GET', - path: `/${indexNames ? indexNames : '*'}`, + path: `/${indexNamesCSV}`, query: { expand_wildcards: 'hidden,all', }, @@ -57,18 +65,17 @@ async function fetchIndicesCall( format: 'json', h: 'health,status,index,uuid,pri,rep,docs.count,sth,store.size', expand_wildcards: 'hidden,all', + index: indexNamesCSV, }; - if (indexNames) { - catQuery.index = indexNames.join(','); - } - + // This call retrieves health and other high-level information about indices. const catHits: Hit[] = await callAsCurrentUser('transport.request', { method: 'GET', path: '/_cat/indices', query: catQuery, }); + // The two responses should be equal in the number of indices returned return catHits.map(hit => { const index = indices[hit.index]; const aliases = Object.keys(index.aliases); @@ -94,6 +101,6 @@ export const fetchIndices = async ( indexDataEnricher: IndexDataEnricher, indexNames?: string[] ) => { - const response = await fetchIndicesCall(callAsCurrentUser, indexNames); - return await indexDataEnricher.enrichIndices(response, callAsCurrentUser); + const indices = await fetchIndicesCall(callAsCurrentUser, indexNames); + return await indexDataEnricher.enrichIndices(indices, callAsCurrentUser); }; diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 149c13ea55fb2..31fdc189b7539 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -6736,7 +6736,6 @@ "xpack.idxMgmt.indexTable.serverErrorTitle": "インデックスの読み込み中にエラーが発生", "xpack.idxMgmt.indexTable.systemIndicesSearchIndicesAriaLabel": "インデックスの検索", "xpack.idxMgmt.indexTable.systemIndicesSearchInputPlaceholder": "検索", - "xpack.idxMgmt.indexTable.systemIndicesSwitchLabel": "システムインデックスを含める", "xpack.idxMgmt.indexTemplatesList.emptyPrompt.noIndexTemplatesTitle": "まだテンプレートがありません", "xpack.idxMgmt.indexTemplatesList.loadingIndexTemplatesDescription": "テンプレートを読み込み中…", "xpack.idxMgmt.indexTemplatesList.loadingIndexTemplatesErrorMessage": "テンプレートの読み込み中にエラーが発生", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index bd22f2a14a292..dae498cf7dd07 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -6741,7 +6741,6 @@ "xpack.idxMgmt.indexTable.serverErrorTitle": "加载索引时出错", "xpack.idxMgmt.indexTable.systemIndicesSearchIndicesAriaLabel": "搜索索引", "xpack.idxMgmt.indexTable.systemIndicesSearchInputPlaceholder": "搜索", - "xpack.idxMgmt.indexTable.systemIndicesSwitchLabel": "包括系统索引", "xpack.idxMgmt.indexTemplatesList.emptyPrompt.noIndexTemplatesTitle": "您尚未有任何模板", "xpack.idxMgmt.indexTemplatesList.loadingIndexTemplatesDescription": "正在加载模板……", "xpack.idxMgmt.indexTemplatesList.loadingIndexTemplatesErrorMessage": "加载模板时出错", diff --git a/x-pack/test/api_integration/apis/management/index_management/indices.js b/x-pack/test/api_integration/apis/management/index_management/indices.js index ac50a20b02e3b..5d523262d7f10 100644 --- a/x-pack/test/api_integration/apis/management/index_management/indices.js +++ b/x-pack/test/api_integration/apis/management/index_management/indices.js @@ -184,6 +184,7 @@ export default function({ getService }) { const { body } = await list().expect(200); const expectedKeys = [ 'health', + 'hidden', 'status', 'name', 'uuid', @@ -214,6 +215,7 @@ export default function({ getService }) { const { body } = await reload().expect(200); const expectedKeys = [ 'health', + 'hidden', 'status', 'name', 'uuid',