Title: Elasticsearch 8.x compatibility issue: persistence-elastic hook fails with TypeError on bulk indexing · Issue #3385 · secureCodeBox/secureCodeBox · GitHub
Open Graph Title: Elasticsearch 8.x compatibility issue: persistence-elastic hook fails with TypeError on bulk indexing · Issue #3385 · secureCodeBox/secureCodeBox
X Title: Elasticsearch 8.x compatibility issue: persistence-elastic hook fails with TypeError on bulk indexing · Issue #3385 · secureCodeBox/secureCodeBox
Description: Description The persistence-elastic hook (version 5.2.0) fails when attempting to persist scan findings to Elasticsearch 8.x due to an API response format incompatibility. The hook works correctly with Elasticsearch 7.x but crashes with ...
Open Graph Description: Description The persistence-elastic hook (version 5.2.0) fails when attempting to persist scan findings to Elasticsearch 8.x due to an API response format incompatibility. The hook works correctly ...
X Description: Description The persistence-elastic hook (version 5.2.0) fails when attempting to persist scan findings to Elasticsearch 8.x due to an API response format incompatibility. The hook works correctly ...
Opengraph URL: https://github.com/secureCodeBox/secureCodeBox/issues/3385
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Elasticsearch 8.x compatibility issue: persistence-elastic hook fails with TypeError on bulk indexing","articleBody":"## Description\n\nThe `persistence-elastic` hook (version 5.2.0) fails when attempting to persist scan findings to Elasticsearch 8.x due to an API response format incompatibility. The hook works correctly with Elasticsearch 7.x but crashes with a `TypeError` when using Elasticsearch 8.5.1 or later.\n\n \n\n## Error Message\n\nTypeError: Cannot read properties of undefined (reading 'errors') at handle (file:///home/app/hook-wrapper/hook/hook.js:110:22)\n\n \n\n \n\n## Impact\n\n \n\n- **Severity:** Medium\n\n- **Affected Users:** users running Elasticsearch 8.x with persistence-elastic hook\n\n- **Functionality:** Complete persistence failure - findings are not indexed in Elasticsearch\n\n- **Workaround:** Downgrade to Elasticsearch 7.17.x (not ideal for production)\n\n \n\n## Steps to Reproduce\n\n \n\n ```bash\n\n helm install elasticsearch elastic/elasticsearch \\\n\n --version 8.5.1 \\\n\n --set replicas=1 \\\n\n --namespace default\n\n \n\nhelm install persistence-elastic \\\n\n oci://[ghcr.io/securecodebox/helm/persistence-elastic](http://ghcr.io/securecodebox/helm/persistence-elastic) \\\n\n --version 5.2.0 \\\n\n --namespace default\n\n \n\nkubectl apply -f - \u003c\u003cEOF\n\napiVersion: \"[execution.securecodebox.io/v1](http://execution.securecodebox.io/v1)\"\n\nkind: Scan\n\nmetadata:\n\n name: trivy-test\n\nspec:\n\n scanType: \"trivy-image\"\n\n parameters:\n\n - \"nginx:latest\"\n\nEOF\n\n \n\nkubectl logs -l [app.kubernetes.io/name=persistence-elastic](http://app.kubernetes.io/name=persistence-elastic)\n\n \n\n \n\nExpected Behavior\n\nThe persistence hook should successfully index findings to Elasticsearch 8.x, just as it does with Elasticsearch 7.x.\n\n \n\nActual Behavior\n\nThe persistence hook crashes with TypeError: Cannot read properties of undefined (reading 'errors') when attempting to process the Elasticsearch bulk API response.\n\n \n\nRoot Cause Analysis\n\nThe issue is in the hook's handling of the Elasticsearch bulk API response. The response format changed between Elasticsearch 7.x and 8.x:\n\n \n\nElasticsearch 7.x response:\n\n{\n\n body: {\n\n errors: false,\n\n items: [...]\n\n }\n\n}\n\n \n\nElasticsearch 8.x response:\n\n{\n\n errors: false,\n\n items: [...]\n\n // No .body wrapper\n\n}\n\n \n\nCurrent hook code (approximately line 110 in hook.js):\n\nconst { body: bulkResponse } = await client.bulk({ refresh: true, body });\n\n \n\nif (bulkResponse.errors) { // ← TypeError here when bulkResponse is undefined\n\n console.error(\"Bulk Request had errors:\");\n\n console.log(bulkResponse);\n\n}\n\n \n\n \n\nWhen using Elasticsearch 8.x, the destructuring { body: bulkResponse } results in bulkResponse being undefined because the response doesn't have a .body property. This causes the TypeError when trying to access bulkResponse.errors.\n\n \n\nProposed Solution\n\nImplement a backwards-compatible fix that works with both Elasticsearch 7.x and 8.x:\n\n \n\n// Proposed fix for hook.js around line 110\n\nconst response = await client.bulk({ refresh: true, body });\n\n \n\n// Support both ES 7.x (response.body) and ES 8.x (response directly)\n\nconst bulkResponse = response.body || response;\n\n \n\nif (bulkResponse.errors) {\n\n console.error(\"Bulk Request had errors:\");\n\n console.log(bulkResponse);\n\n}\n\n \n\nThis change:\n\n \n\n✅ Works with Elasticsearch 7.x (uses response.body)\n\n✅ Works with Elasticsearch 8.x (uses response directly)\n\n✅ No breaking changes to existing functionality\n\n✅ Simple one-line fix\n\n✅ Follows the pattern used by Elasticsearch's official Node.js client migration guide\n\nEnvironment\n\nSecureCodeBox Version: 4.9.0\n\npersistence-elastic Hook Version: 5.2.0\n\nElasticsearch Version: 8.5.1 (issue occurs), 7.17.3 (works correctly)\n\nKubernetes Version: 1.28\n\nInstallation Method: Helm\n\n \n\n \n\nWorkaround\n\nCurrently, the only workaround is to downgrade Elasticsearch to version 7.17.x:\n\nhelm install elasticsearch elastic/elasticsearch \\\n\n --version 7.17.3 \\\n\n --namespace default\n\n \n\n \n\nHowever, this prevents users from:\n\n \n\nUsing Elasticsearch 8.x features\n\nFollowing Elasticsearch's recommended upgrade path\n\nReceiving security updates for Elasticsearch 8.x\n\nAdditional Context\n\nAffected scanners: All scanners that produce findings (Trivy, Semgrep, Nmap, custom scanners)\n\n \n\nChunk size impact: The error occurs when processing chunks of findings. In our testing:\n\n \n\n0 findings: Hook succeeds (no bulk operation)\n\n1-50 findings: Hook crashes on first bulk operation\n\n50+ findings: Hook crashes on first chunk (50 findings per chunk)\n\n \n\nrelated Elasticsearch migration documentation:\n\n \n\n[Elasticsearch 8.0 Breaking Changes](vscode-file://vscode-app/c:/Users/GKY24/Downloads/VSCode-win32-x64-1.104.1/resources/app/out/vs/code/electron-browser/workbench/workbench.html)\n\n[Elasticsearch Node.js Client Migration](vscode-file://vscode-app/c:/Users/GKY24/Downloads/VSCode-win32-x64-1.104.1/resources/app/out/vs/code/electron-browser/workbench/workbench.html)\n\n \n\nRequest\n\nPlease consider implementing the proposed backwards-compatible fix in the next release of the persistence-elastic hook. This will enable users to use Elasticsearch 8.x while maintaining compatibility with 7.x installations.\n\n \n\nThank you for maintaining this excellent project! 🙏","author":{"url":"https://github.com/conleth","@type":"Person","name":"conleth"},"datePublished":"2025-11-21T23:13:07.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/3385/secureCodeBox/issues/3385"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0eb5a687-753d-0dee-7c87-a948be5e8fc1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E4A2:2D3E98:7540A9F:97AEBC1:6975B332 |
| html-safe-nonce | 3093ee77c72db1f6f6547d25b0179bd4f27974e22253ba42228cdc838bd815dd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNEEyOjJEM0U5ODo3NTQwQTlGOjk3QUVCQzE6Njk3NUIzMzIiLCJ2aXNpdG9yX2lkIjoiMzY5NjkwMzU4NDg4NTYzNzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4a2b0c6b761e3ad5742c061f6d55adaecff78da33a814c0e7f8f32cd0df53375 |
| hovercard-subject-tag | issue:3653355188 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/secureCodeBox/secureCodeBox/3385/issue_layout |
| twitter:image | https://opengraph.githubassets.com/753b5f457a8cfb61eb022387b282727b40da738c873ae1350db5be89c89c1fa1/secureCodeBox/secureCodeBox/issues/3385 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/753b5f457a8cfb61eb022387b282727b40da738c873ae1350db5be89c89c1fa1/secureCodeBox/secureCodeBox/issues/3385 |
| og:image:alt | Description The persistence-elastic hook (version 5.2.0) fails when attempting to persist scan findings to Elasticsearch 8.x due to an API response format incompatibility. The hook works correctly ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | conleth |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4a4bf5f4e28041a9d2e5c107d7d20b78b4294ba261cab243b28167c16a623a1f |
| turbo-cache-control | no-preview |
| go-import | github.com/secureCodeBox/secureCodeBox git https://github.com/secureCodeBox/secureCodeBox.git |
| octolytics-dimension-user_id | 34573705 |
| octolytics-dimension-user_login | secureCodeBox |
| octolytics-dimension-repository_id | 80711933 |
| octolytics-dimension-repository_nwo | secureCodeBox/secureCodeBox |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 80711933 |
| octolytics-dimension-repository_network_root_nwo | secureCodeBox/secureCodeBox |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 488b30e96dfd057fbbe44c6665ccbc030b729dde |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width