Skip to content

RI-8316 Match key type when finding indexes for a key#6200

Open
dantovska wants to merge 1 commit into
mainfrom
be/bugfix/RI-8316/match-key-type-in-key-indexes
Open

RI-8316 Match key type when finding indexes for a key#6200
dantovska wants to merge 1 commit into
mainfrom
be/bugfix/RI-8316/match-key-type-in-key-indexes

Conversation

@dantovska

@dantovska dantovska commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

What

The redisearch/key-indexes endpoint (behind "View index" / "Make searchable" in the key details panel) matched indexes by prefix only — the index definition's key_type was returned but never compared. A JSON key like foo:bar therefore matched an FT.CREATE … ON HASH PREFIX 1 "foo:" index and the panel showed "View index" for an index that will never cover that key.

The service now resolves the key's type with TYPE and only returns indexes whose key_type matches (hashHASH, ReJSON-RLJSON); keys of unsearchable types short-circuit to no matches. Empty-prefix ("match all") indexes also respect the key type now. No API shape change.

Also fixes the cluster-dedup unit test, which mocked FT.INFO on the wrong client and only passed because an undefined reply degraded to an empty (match-all) definition — the new type check exposed it.

Testing

  • Unit: key-indexes.service.spec.ts — existing cases updated to mock TYPE, plus new cases: HASH index vs JSON key → no match, empty-prefix index respects key type, unsupported key type returns empty without listing indexes (33 backend redisearch tests pass).
  • Manual against a live database: FT.CREATE idx ON HASH PREFIX 1 "x:" + HSET x:h … + JSON.SET x:j … → key-indexes returns the index for x:h and nothing for x:j (previously both matched).

Closes #RI-8316

🤖 Generated with Claude Code


Note

Low Risk
Scoped browser API behavior fix with no response shape change; adds one TYPE round-trip per lookup for searchable key types only.

Overview
getKeyIndexes no longer treats prefix overlap as enough to link a key to a RediSearch index. It runs TYPE on the key first, maps hash / ReJSON-RL to the index definition’s HASH / JSON, and only keeps indexes whose key_type matches. Prefix rules are unchanged, including empty-prefix indexes, but those now also require the same type. Keys that aren’t HASH or JSON return an empty list without calling FT._LIST.

Unit tests mock TYPE via a shared helper, add cases for type mismatch and unsupported types, and fix cluster dedup by stubbing FT.INFO on the shard client that actually runs it.

Reviewed by Cursor Bugbot for commit 5409235. Bugbot is set up for automated code reviews on this repo. Configure here.

@dantovska dantovska requested a review from a team as a code owner July 13, 2026 17:24
@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Code Coverage - Backend unit tests

St.
Category Percentage Covered / Total
🟢 Statements 93.14% 16552/17772
🟡 Branches 75.32% 5284/7015
🟢 Functions 87.46% 2538/2902
🟢 Lines 93% 15827/17019

Test suite run success

3692 tests passing in 321 suites.

Report generated by 🧪jest coverage report action from 5409235

The key-indexes endpoint matched indexes by prefix only, so a JSON key
matched FT.CREATE ... ON HASH indexes with the same prefix and the key
details panel wrongly offered "View index". Resolve the key's type via
TYPE and require it to match the index definition's key_type; keys of
unsearchable types return no indexes.

Fixes #RI-8316

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@dantovska dantovska force-pushed the be/bugfix/RI-8316/match-key-type-in-key-indexes branch from 48eaa9d to 5409235 Compare July 14, 2026 16:02

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5409235426

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +57 to +58
if (!indexKeyType) {
return plainToInstance(KeyIndexesResponse, { indexes: [] });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle key names that have no Redis type

When the requested key does not currently exist, TYPE returns none, so this early return skips FT._LIST/FT.INFO and reports no indexes. The existing POST /redisearch/key-indexes integration setup passes ${TEST_SEARCH_HASH_KEY_PREFIX_1}1 while generateRedisearchIndexes only creates no-prefix HASH indexes, so that endpoint now returns [] instead of TEST_SEARCH_HASH_INDEX_1 for the tested key-name lookup scenario.

Useful? React with 👍 / 👎.

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.

1 participant