diff --git a/public/components/event_analytics/explorer/query_assist/__tests__/hooks.test.ts b/public/components/event_analytics/explorer/query_assist/__tests__/hooks.test.ts index 45e910d02..40df79e14 100644 --- a/public/components/event_analytics/explorer/query_assist/__tests__/hooks.test.ts +++ b/public/components/event_analytics/explorer/query_assist/__tests__/hooks.test.ts @@ -33,6 +33,16 @@ describe('useCatIndices', () => { expect(result.current.data).toEqual([{ label: 'test1' }, { label: 'test2' }]); }); + it('should hide indices starting with dot', async () => { + httpMock.get.mockResolvedValueOnce([{ index: '.test1' }, { index: 'test2' }]); + + const { result, waitForNextUpdate } = renderHook(() => useCatIndices()); + expect(result.current.loading).toBe(true); + await waitForNextUpdate(); + expect(result.current.loading).toBe(false); + expect(result.current.data).toEqual([{ label: 'test2' }]); + }); + it('should handle errors', async () => { httpMock.get.mockRejectedValueOnce('API failed'); diff --git a/public/components/event_analytics/explorer/query_assist/hooks.ts b/public/components/event_analytics/explorer/query_assist/hooks.ts index 281f659ba..0dd2dda21 100644 --- a/public/components/event_analytics/explorer/query_assist/hooks.ts +++ b/public/components/event_analytics/explorer/query_assist/hooks.ts @@ -5,7 +5,7 @@ import { EuiComboBoxOptionOption } from '@elastic/eui'; import { CatIndicesResponse } from '@opensearch-project/opensearch/api/types'; -import { Reducer, useReducer, useState, useEffect } from 'react'; +import { Reducer, useEffect, useReducer, useState } from 'react'; import { IndexPatternAttributes } from '../../../../../../../src/plugins/data/common'; import { DSL_BASE, DSL_CAT } from '../../../../../common/constants/shared'; import { getOSDHttp } from '../../../../../common/utils'; @@ -48,7 +48,12 @@ export const useCatIndices = () => { getOSDHttp() .get(`${DSL_BASE}${DSL_CAT}`, { query: { format: 'json' }, signal: abortController.signal }) .then((payload: CatIndicesResponse) => - dispatch({ type: 'success', payload: payload.map((meta) => ({ label: meta.index! })) }) + dispatch({ + type: 'success', + payload: payload + .filter((meta) => meta.index && !meta.index.startsWith('.')) + .map((meta) => ({ label: meta.index! })), + }) ) .catch((error) => dispatch({ type: 'failure', error }));