diff --git a/x-pack/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_indices.test.ts b/x-pack/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_indices.test.ts index e7eaa75407248..d5e92cb8d682e 100644 --- a/x-pack/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_indices.test.ts +++ b/x-pack/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_indices.test.ts @@ -12,12 +12,15 @@ import { getGetKnowledgeBaseIndicesRequest } from '../../__mocks__/request'; const mockFieldCaps = { indices: [ - '.ds-logs-endpoint.alerts-default-2024.10.31-000001', - '.ds-metrics-endpoint.metadata-default-2024.10.31-000001', - '.internal.alerts-security.alerts-default-000001', + '.ds-.items-default-2024.11.12-000001', + '.ds-.lists-default-2024.11.12-000001', + '.ds-logs-endpoint.alerts-default-2024.11.12-000001', + '.ds-logs-endpoint.events.process-default-2024.11.12-000001', + 'gtr-1', + 'gtr-with-bug', + 'gtr-with-semantic-1', 'metrics-endpoint.metadata_current_default', - 'semantic-index-1', - 'semantic-index-2', + 'search-elastic-security-docs', ], fields: { content: { @@ -27,9 +30,12 @@ const mockFieldCaps = { searchable: false, aggregatable: false, indices: [ - '.ds-logs-endpoint.alerts-default-2024.10.31-000001', - '.ds-metrics-endpoint.metadata-default-2024.10.31-000001', - '.internal.alerts-security.alerts-default-000001', + '.ds-.items-default-2024.11.12-000001', + '.ds-.lists-default-2024.11.12-000001', + '.ds-logs-endpoint.alerts-default-2024.11.12-000001', + '.ds-logs-endpoint.events.process-default-2024.11.12-000001', + 'gtr-1', + 'gtr-with-bug', 'metrics-endpoint.metadata_current_default', ], }, @@ -38,7 +44,55 @@ const mockFieldCaps = { metadata_field: false, searchable: true, aggregatable: false, - indices: ['semantic-index-1', 'semantic-index-2'], + indices: ['gtr-with-semantic-1'], + }, + }, + ai_embeddings: { + unmapped: { + type: 'unmapped', + metadata_field: false, + searchable: false, + aggregatable: false, + indices: [ + '.ds-.items-default-2024.11.12-000001', + '.ds-.lists-default-2024.11.12-000001', + '.ds-logs-endpoint.alerts-default-2024.11.12-000001', + '.ds-logs-endpoint.events.process-default-2024.11.12-000001', + 'gtr-1', + 'gtr-with-semantic-1', + 'metrics-endpoint.metadata_current_default', + ], + }, + semantic_text: { + type: 'semantic_text', + metadata_field: false, + searchable: true, + aggregatable: false, + indices: ['gtr-with-bug', 'search-elastic-security-docs'], + }, + }, + semantic_text: { + unmapped: { + type: 'unmapped', + metadata_field: false, + searchable: false, + aggregatable: false, + indices: [ + '.ds-.items-default-2024.11.12-000001', + '.ds-.lists-default-2024.11.12-000001', + '.ds-logs-endpoint.alerts-default-2024.11.12-000001', + '.ds-logs-endpoint.events.process-default-2024.11.12-000001', + 'gtr-1', + 'gtr-with-semantic-1', + 'metrics-endpoint.metadata_current_default', + ], + }, + semantic_text: { + type: 'semantic_text', + metadata_field: false, + searchable: true, + aggregatable: false, + indices: ['search-elastic-security-docs'], }, }, }, @@ -66,7 +120,7 @@ describe('Get Knowledge Base Status Route', () => { expect(response.status).toEqual(200); expect(response.body).toEqual({ - indices: ['semantic-index-1', 'semantic-index-2'], + indices: ['gtr-with-bug', 'gtr-with-semantic-1', 'search-elastic-security-docs'], }); expect(context.core.elasticsearch.client.asCurrentUser.fieldCaps).toBeCalledWith({ index: '*', diff --git a/x-pack/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_indices.ts b/x-pack/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_indices.ts index 18191291468de..5106c31d39e7d 100644 --- a/x-pack/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_indices.ts +++ b/x-pack/plugins/elastic_assistant/server/routes/knowledge_base/get_knowledge_base_indices.ts @@ -53,10 +53,10 @@ export const getKnowledgeBaseIndicesRoute = (router: ElasticAssistantPluginRoute include_unmapped: true, }); - const indices = res.fields.content?.semantic_text?.indices; - if (indices) { - body.indices = Array.isArray(indices) ? indices : [indices]; - } + body.indices = Object.values(res.fields) + .flatMap((value) => value.semantic_text?.indices ?? []) + .filter((value, index, self) => self.indexOf(value) === index) + .sort(); return response.ok({ body }); } catch (err) {