fix: resolve case alert attachments via ids-query search (rolled-over alias) - #56
Merged
Merged
Conversation
GET _doc/{id} and _mget are single-index operations: they fail with
'alias has more than one index associated with it' once ILM rolls the
alerts alias over, so on any long-lived cluster attachment enrichment
rendered every alert as 'Unknown rule' and attachAlertsByIds silently
attached 0 alerts.
Replace both lookups with one _search + ids query over the recorded
indices (works through multi-backing-index aliases, and batches up to
20 per-alert GETs into a single request). Failed lookups are now logged
via the injectable stderr Logger instead of being swallowed. Alert ids
are deduplicated before the lookup and the search size is clamped to
the max_result_window default.
Fixes #55
niros1
approved these changes
Jul 8, 2026
davethegut
approved these changes
Jul 8, 2026
davethegut
left a comment
Collaborator
There was a problem hiding this comment.
tested and works! lgtm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #55. On any cluster whose security alerts index has rolled over (which ILM does on every long-lived cluster), three case flows degraded silently:
Unknown rule/Lowcreate-casewithalertIds/approve-discoveriesreported success but attached 0 alertsRoot cause: attachment enrichment used
GET /{index}/_doc/{id}and the attach lookup used_mgetagainst the.alerts-security.alerts-defaultalias. Both are single-index operations, so once the alias points at 2+ backing indices ES rejects every call withalias [...] has more than one index associated with it, can't execute a single index op— and both call sites swallowed the error.Fix: replace both with a single
_search+idsquery (searchAlertsByIds) over the attachments' recorded indices. A search fans out across all backing indices, accepts alias and concrete index names alike, and batches up to 20 per-alert GETs into one request. Failed lookups are now logged via the injectable stderrLogger(same pattern astelemetryService) instead of vanishing.Changes
src/elastic/client/casesClient.ts—searchAlertsByIds(indices, ids)replacesgetAlertDocument+mgetAlerts;sizeclamped to themax_result_windowdefault (10 000)src/elastic/service/casesService.ts—getCaseAlertsenriches via one batched search over the deduplicated recorded indices;attachAlertsByIdsdedups ids and uses the same search; both log lookup failures via injectedlogger(defaultcreateStderrLogger(["cases"]))Behavioral notes
_searchis near-realtime whereGET/_mgetwere realtime — negligible here since Kibana writes alerts with refresh and both flows operate on minutes-old alerts_indexfrom the search hit — stored attachment shape unchangedTest plan
npx vitest run— 409/409 passing; typecheck and lint clean_rolloveron.alerts-security.alerts-default(alias → 000001+000002), created a case with 3 attached alerts → app showedUnknown rule/Low; with this fix the same case shows real rule names and severities (verified in Claude Desktop via MCPB build)ids-query search returns full docs through the rolled-over alias on the customer-reported cluster as well