diff --git a/x-pack/plugins/observability_ai_assistant/public/functions/get_dataset_info.ts b/x-pack/plugins/observability_ai_assistant/public/functions/get_dataset_info.ts index e2701965e2b195..c4838c7e920cc2 100644 --- a/x-pack/plugins/observability_ai_assistant/public/functions/get_dataset_info.ts +++ b/x-pack/plugins/observability_ai_assistant/public/functions/get_dataset_info.ts @@ -23,6 +23,7 @@ export function registerGetDatasetInfoFunction({ description: `Use this function to get information about indices/datasets available and the fields available on them. providing empty string as index name will retrieve all indices + if index is provided and it doesnt match any indices in elasticsearch list of all indices will be provoded as well else list of all fields for the given index will be given. wildcards can be part of index name. diff --git a/x-pack/plugins/observability_ai_assistant/server/service/client/index.ts b/x-pack/plugins/observability_ai_assistant/server/service/client/index.ts index e06c6f7200480a..78ab8357732ccc 100644 --- a/x-pack/plugins/observability_ai_assistant/server/service/client/index.ts +++ b/x-pack/plugins/observability_ai_assistant/server/service/client/index.ts @@ -374,6 +374,23 @@ export class ObservabilityAIAssistantClient { }; } + if (indices.length === 0) { + try { + const body = await this.dependencies.esClient.indices.resolveIndex({ + name: '*', + expand_wildcards: 'open', + }); + indices = body.indices.map((i) => i.name); + } catch (e) { + indices = []; + } + + return { + indices, + fields: [], + }; + } + const fields = await this.dependencies.dataviews.getFieldsForWildcard({ pattern: index, });