diff --git a/src/plugins/data/public/query/query_string/dataset_service/lib/index_type.ts b/src/plugins/data/public/query/query_string/dataset_service/lib/index_type.ts index 655d3720dab2..272db09eabe8 100644 --- a/src/plugins/data/public/query/query_string/dataset_service/lib/index_type.ts +++ b/src/plugins/data/public/query/query_string/dataset_service/lib/index_type.ts @@ -120,11 +120,17 @@ const fetchDataSources = async (client: SavedObjectsClientContract) => { perPage: 10000, }); const dataSources: DataStructure[] = [DEFAULT_DATA.STRUCTURES.LOCAL_DATASOURCE].concat( - response.savedObjects.map((savedObject) => ({ - id: savedObject.id, - title: savedObject.attributes.title, - type: 'DATA_SOURCE', - })) + response.savedObjects + .filter( + (savedObject) => + typeof savedObject.attributes?.dataSourceEngineType === 'string' && + !savedObject.attributes?.dataSourceEngineType?.includes('OpenSearch Serverless') + ) + .map((savedObject) => ({ + id: savedObject.id, + title: savedObject.attributes.title, + type: 'DATA_SOURCE', + })) ); return injectMetaToDataStructures(dataSources); diff --git a/src/plugins/query_enhancements/public/datasets/s3_type.test.ts b/src/plugins/query_enhancements/public/datasets/s3_type.test.ts index 419c5a6344f1..3f085c135f28 100644 --- a/src/plugins/query_enhancements/public/datasets/s3_type.test.ts +++ b/src/plugins/query_enhancements/public/datasets/s3_type.test.ts @@ -141,7 +141,9 @@ describe('s3TypeConfig', () => { it('should fetch data sources for unknown type', async () => { mockSavedObjectsClient.find = jest.fn().mockResolvedValue({ - savedObjects: [{ id: 'ds1', attributes: { title: 'DataSource 1' } }], + savedObjects: [ + { id: 'ds1', attributes: { title: 'DataSource 1', dataSourceEngineType: 'OpenSearch' } }, + ], }); const result = await s3TypeConfig.fetch(mockServices as IDataPluginServices, [ @@ -152,6 +154,29 @@ describe('s3TypeConfig', () => { expect(result.children?.[1].title).toBe('DataSource 1'); expect(result.hasNext).toBe(true); }); + + it('should filter out OpenSearch Serverless data sources', async () => { + mockSavedObjectsClient.find = jest.fn().mockResolvedValue({ + savedObjects: [ + { id: 'ds1', attributes: { title: 'DataSource 1', dataSourceEngineType: 'OpenSearch' } }, + { + id: 'ds2', + attributes: { title: 'DataSource 2', dataSourceEngineType: 'OpenSearch Serverless' }, + }, + { id: 'ds3', attributes: { title: 'DataSource 3', dataSourceEngineType: 'OpenSearch' } }, + ], + }); + + const result = await s3TypeConfig.fetch(mockServices as IDataPluginServices, [ + { id: 'unknown', title: 'Unknown', type: 'UNKNOWN' }, + ]); + + expect(result.children).toHaveLength(3); // Including DEFAULT_DATA.STRUCTURES.LOCAL_DATASOURCE + expect(result.children?.[1].title).toBe('DataSource 1'); + expect(result.children?.[2].title).toBe('DataSource 3'); + expect(result.children?.some((child) => child.title === 'DataSource 2')).toBe(false); + expect(result.hasNext).toBe(true); + }); }); test('fetchFields returns table fields', async () => { diff --git a/src/plugins/query_enhancements/public/datasets/s3_type.ts b/src/plugins/query_enhancements/public/datasets/s3_type.ts index ec73c5372017..a62f2d21cecc 100644 --- a/src/plugins/query_enhancements/public/datasets/s3_type.ts +++ b/src/plugins/query_enhancements/public/datasets/s3_type.ts @@ -198,17 +198,23 @@ const fetchDataSources = async (client: SavedObjectsClientContract): Promise ({ - id: savedObject.id, - title: savedObject.attributes.title, - type: 'DATA_SOURCE', - meta: { - query: { - id: savedObject.id, - }, - type: DATA_STRUCTURE_META_TYPES.CUSTOM, - } as DataStructureCustomMeta, - })) + resp.savedObjects + .filter( + (savedObject) => + typeof savedObject.attributes?.dataSourceEngineType === 'string' && + !savedObject.attributes?.dataSourceEngineType?.includes('OpenSearch Serverless') + ) + .map((savedObject) => ({ + id: savedObject.id, + title: savedObject.attributes.title, + type: 'DATA_SOURCE', + meta: { + query: { + id: savedObject.id, + }, + type: DATA_STRUCTURE_META_TYPES.CUSTOM, + } as DataStructureCustomMeta, + })) ); };