Fix Kibana Discover URL when query_key value is empty or a single-item array#1769
Merged
jertel merged 2 commits intoJul 14, 2026
Merged
Conversation
Elasticsearch returns multi-valued fields as arrays even when they carry
a single value, and rules using such fields as `query_key` render Kibana
filters with `params.query: ['']` — a phrase filter that matches no
documents. The reviewer follows the "Kibana link" from an alert into an
empty Discover view.
Normalise the `query_key` value before filter emission:
- None, '', [], [''], [None, ''] -> emit the existing negate-exists
filter (matches previous behaviour for missing values)
- ['single'] -> unwrap to 'single' and emit the
same phrase filter as the scalar case
- Multi-value lists -> passed through unchanged so
existing behaviour is preserved
No existing test-cases change; five new parametric tests cover the empty
scalar/list cases (all asserting the same URL as the current `null`
test), and one new test covers the single-element list unwrap (asserting
the same URL as the current `str_query_key` test).
Signed-off-by: John Ramacher <john.ramacher@wise.com>
Fix discover URLs for empty query_key values and update changelog.
jertel
approved these changes
Jul 14, 2026
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.
Description
Elasticsearch returns multi-valued fields as arrays even when they carry a single value. When a rule uses such a field as
query_key,kibana_discover_app_state()currently emits a Kibana filter likeparams.query: ['']— a phrase filter that matches no documents. The reviewer follows the Kibana link from the alert and lands on an empty Discover view, which reads as a broken link.Reproduction
query_key: [db.name, user.name, cloud.instance.name, service.environment]db.name = [""],user.name = [""],cloud.instance.name = "platon",service.environment = "production"params.query: !('')fordb.nameanduser.name, decoded from Rison asparams.query: ['']. Kibana renders these as active filters, silently returns zero results.Fix
Add a small normaliser and apply it to each
query_keyvalue before filter emission:None,'',[],[''],[None, '']→ collapse toNone. Existing code path emits a negate-exists filter (matching the current behaviour for missing values).['single']→ unwrap to'single'. Existing code path emits the same phrase filter as the scalar case.['a', 'b']) → passed through unchanged. Behaviour matches today's code so this PR does not attempt to change how those render.Diff shape
elastalert/kibana_discover.py: +32 / -0. No existing logic paths deleted.tests/kibana_discover_test.py: +126 / -0. Six new tests, no existing tests modified.CHANGELOG.md: 1-line note under2.TBD.TBD→ Other changes.Checklist
make test-dockerwith my changes. All tests pass; docs build clean.Questions or Comments
New tests are parametric so they read as one block for the empty-value cases and mirror the existing
null_query_key_valueandstr_query_keytests' expected URLs — deliberately keeping the assertions surface small and consistent with the file's existing style.Multi-value list handling (rendering as a
phrases/"IS ONE OF" filter) is deliberately out of scope for this PR: current behaviour is preserved, the change here is narrow, and a follow-up can add proper multi-value support later.