Render displays for documents matched through index aliases - #44
Open
RusticRoman wants to merge 2 commits into
Open
Render displays for documents matched through index aliases#44RusticRoman wants to merge 2 commits into
RusticRoman wants to merge 2 commits into
Conversation
When a workspace or display named an alias in its index_pattern, document cards fell back to raw JSON instead of the display template. Displays were matched by compiling the index pattern into a regex and testing it against the hit's _index, which reports the concrete backing index, so an alias never matched and the template was undefined. Add GET /api/content/aliases/<index_patterns> (and the matching MCP tool) to report the aliases of each index, and match a document against both its index name and its aliases, preferring a display that names the index itself. Alias resolution is fetched once per workspace and degrades to index-name matching if it fails. The matching logic was copy-pasted across four components, so it moves to utils and a useDisplays hook that all four now share. Consolidating it also fixes three latent defects in that logic: regex metacharacters in an index pattern were not escaped, so '.ds-logs-1' matched 'xds-logs-1'; a comma-separated index pattern was compiled as one regex and matched nothing; and an index pattern excluding an index with a leading '-' was treated as a positive match. Fixes elastic#8 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
Author
|
@davemoore- ready for review when you have a moment — this fixes #8 (displays not rendering when |
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.
Fixes #8.
The bug
When a workspace and its displays name an alias in
index_pattern, document cards render as raw JSON instead of the display's markdown template. The reporter worked around it by switching both to concrete index names.Displays are matched to a hit by compiling
index_patterninto a regex and testing it againsthit._index. A hit always reports the concrete backing index (products-000001), never the alias (products), so the pattern never matched,templatecame backundefined, andDocCardfell through to its JSON branch.This also explains the reporter's other observation — that the cards showed only the fields configured on the display. Source filters are aggregated globally across displays and are never index-matched, so
_source.includesapplied correctly; only the per-index template lookup failed.The fix
GET /api/content/aliases/<index_patterns>reports the aliases of each index in a pattern, usingignore_unavailableso one missing index in a comma-separated pattern doesn't discard the aliases of the others. A matchingcontent_aliasesMCP tool keeps the REST/MCP mapping 1:1.The matching logic was copy-pasted across four components, so it moves into
utilsplus auseDisplayshook. Consolidating surfaced three latent defects in that logic, fixed here:.ds-logs-1matchedxds-logs-1.is literal"a,b"compiled to^a,b$, matched nothing"products-*,-products-archive"still matchedproducts-archiveTesting
products-*workspace is unaffected.Known limitation
A filtered alias covers only part of its backing index, but alias membership can't be decided from index metadata alone, so every document of that index matches a display naming the alias. Noted in the endpoint's docstring. Data streams have the same underlying shape and are still unhandled;
_resolve/indexwould cover aliases and data streams with one mechanism if that's worth a follow-up.Separately,
isIndexPatternInWorkspaceScopein the displays form still validates without alias awareness, so a display naming an alias can't be created when the workspace pattern is a concrete wildcard. Left out of scope here — happy to open a follow-up issue.Also carries one unrelated one-line commit:
.idea/added to.gitignore, so JetBrains project files stop showing up as untracked.