From c3f04f93284fc65073869d0fc67a6d4f6bb4e39b Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Fri, 27 Sep 2024 15:38:30 +0200 Subject: [PATCH] fix document import --- .../services/epm/kibana/knowledge_base/install.ts | 12 ++++++++---- .../epm/kibana/knowledge_base/parse_entries.ts | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/epm/kibana/knowledge_base/install.ts b/x-pack/plugins/fleet/server/services/epm/kibana/knowledge_base/install.ts index b90eebe0e7f2c..1821510a80161 100644 --- a/x-pack/plugins/fleet/server/services/epm/kibana/knowledge_base/install.ts +++ b/x-pack/plugins/fleet/server/services/epm/kibana/knowledge_base/install.ts @@ -113,7 +113,7 @@ async function installKibanaKnowledgeBaseEntry( await savedObjectsClient.create( knowledgeBaseEntrySavedObjectType, { - // TODO: update the mappings / props once the KB PR has been merged + // TODO: update the props to the full set once the KB PR has been merged name: entry.manifest.name, type: 'index', description: entry.manifest.description, @@ -133,9 +133,13 @@ const indexContentFile = async ({ }) => { const fileContent = contentBuffer.toString('utf-8'); const lines = fileContent.split('\n'); - const documents = lines.map((line) => { - return JSON.parse(line.trim()); - }); + + const documents = lines + .map((line) => line.trim()) + .filter((line) => line.length > 0) + .map((line) => { + return JSON.parse(line); + }); const operations = documents.reduce((ops, document) => { ops!.push(...[{ index: { _index: indexName } }, document]); diff --git a/x-pack/plugins/fleet/server/services/epm/kibana/knowledge_base/parse_entries.ts b/x-pack/plugins/fleet/server/services/epm/kibana/knowledge_base/parse_entries.ts index bc4f40290a2c0..832fd85b4d56c 100644 --- a/x-pack/plugins/fleet/server/services/epm/kibana/knowledge_base/parse_entries.ts +++ b/x-pack/plugins/fleet/server/services/epm/kibana/knowledge_base/parse_entries.ts @@ -75,7 +75,7 @@ const entryPathsFromManifestPath = (manifestPath: string) => { const splits = manifestPath.split('/'); const rootFolderPath = splits.slice(0, splits.length - 1).join('/'); const entryName = splits[splits.length - 2]; - const contentFolderPath = [...rootFolderPath, 'content'].join('/'); + const contentFolderPath = [rootFolderPath, 'content'].join('/'); return { entryName,