Skip to content

Render displays for documents matched through index aliases - #44

Open
RusticRoman wants to merge 2 commits into
elastic:mainfrom
RusticRoman:fix/display-alias-resolution
Open

Render displays for documents matched through index aliases#44
RusticRoman wants to merge 2 commits into
elastic:mainfrom
RusticRoman:fix/display-alias-resolution

Conversation

@RusticRoman

@RusticRoman RusticRoman commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

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_pattern into a regex and testing it against hit._index. A hit always reports the concrete backing index (products-000001), never the alias (products), so the pattern never matched, template came back undefined, and DocCard fell 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.includes applied 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, using ignore_unavailable so one missing index in a comma-separated pattern doesn't discard the aliases of the others. A matching content_aliases MCP tool keeps the REST/MCP mapping 1:1.
  • A document is matched against both its index name and its aliases, preferring a display that names the index itself so that existing concrete-index displays keep winning.
  • Aliases are fetched once per workspace. If the request fails, matching degrades to index names alone — today's behavior, not a broken page.

The matching logic was copy-pasted across four components, so it moves into utils plus a useDisplays hook. Consolidating surfaced three latent defects in that logic, fixed here:

Defect Before After
Unescaped regex metacharacters .ds-logs-1 matched xds-logs-1 . is literal
Comma-separated pattern "a,b" compiled to ^a,b$, matched nothing one matcher per part
Exclusion term "products-*,-products-archive" still matched products-archive exclusion vetoes the match

Testing

  • Python: 4 new tests for the endpoint; full unit suite green (2352 passed).
  • UI: 25 tests for the matcher and 6 for the hook (alias resolution, failure fallback, non-2xx, stale-response race). Full suite green (62 passed).
  • Guards are mutation-checked: deleting the 404 guard, the non-2xx guard, the missing-index guard, or the stale-response guard each turns a test red.
  • End to end against a real cluster in Docker, with an aliased index and workspace/display naming the alias: cards render the template on the Judgements page, the Strategies test panel, and the evaluation's unrated-docs panel. Verified the same build without the fix reproduces the reported JSON fallback, and that a non-alias 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/index would cover aliases and data streams with one mechanism if that's worth a follow-up.

Separately, isIndexPatternInWorkspaceScope in 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.

RusticRoman and others added 2 commits August 28, 2026 15:24
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>
@RusticRoman

Copy link
Copy Markdown
Contributor Author

@davemoore- ready for review when you have a moment — this fixes #8 (displays not rendering when index_pattern names an alias). Verified end to end against a real cluster, with before/after runs on the same build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Displays do not work properly when using aliases as index_pattern

1 participant