Skip to content

Fixes #31878: return 400 for a search against an index OpenMetadata does not manage - #35516

Merged
manerow merged 1 commit into
mainfrom
fix/31878-unknown-index-400
Oct 16, 2026
Merged

manerow merged 1 commit into
mainfrom
fix/31878-unknown-index-400

Conversation

@manerow

@manerow manerow commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #31878

Problem

A search against an index name OpenMetadata does not have, such as GET /api/v1/search/query?index=nope_search_index, returns 500 Failed to find index nope_search_index. Nothing on the server failed: the caller asked for a name that does not exist. A 500 is logged at ERROR, so a typo in an API client or script shows up as a backend fault in error tracking and in the 5xx rate.

The other cases in #31878 (malformed query text, an out-of-range page) were fixed by PR #33655, which reports the engine's 400 as a 400. A missing index is different: the engine answers 404, and the search managers turn every 404 into SearchIndexNotFoundException, which defaults to 500.

Why not always 400

The same 404 also happens when one of OpenMetadata's own indexes is missing from the cluster, for example an alias left detached by a failed reindex (DefaultRecreateHandler documents this case). That is a real outage and must keep alerting, so it stays a 500.

What this PR changes

When the engine says an index is missing, OpenMetadata now checks whose name it was:

  • A name OpenMetadata does not manage gives 400 Unknown search index [nope_search_index]. The name is reported as the caller typed it, without the cluster prefix.
  • Only managed names keeps the 500 Failed to find index ..., with the same text as today.

"Managed" means any entity type, canonical index name or alias in the index mapping registry. That includes Collate's indexes, which are merged into the same registry. Wildcards and Data Insights names never count as unknown. The set of known names is built once when the mappings load. Nothing is checked before the request reaches the engine, so no request that works today can start failing.

The rule lives in one place, SearchEngineErrors.indexNotFound, and all 10 places that turned a 404 into a 500 now call it. That covers doSearch, searchForExport, doListWithOffset and listWithDeepPagination in both search managers, and getDocByID in both entity managers.

getDocByID (GET /v1/search/get/{index}/doc/{id}) also stops saying Failed to find doc with id ... for a missing index. A missing document never reached that branch: it already returns 404 Document not found., which this PR keeps.

How it was tested

  • SearchIndexUtilsTest: which names count as known, and a table of typed index expressions with and without a cluster alias (table, all, dataAsset, nope_search_index, table,nope, nope*, di-data-assets-table, a prefixed name, an empty registry).
  • SearchEngineErrorsTest: an unknown name gives 400 with the exact message, and a managed index gives 500 with the exact message.
  • SearchResourceIT: index=nope_search_index, index=table_search_index,nope_search_index and /search/get/nope_search_index/doc/... return 400, and a missing document in a real index still returns 404. These pass on Elasticsearch and OpenSearch, together with the existing malformed-input tests (12 of 12 on each engine).
  • The search unit tests around it pass (SearchRepositoryBehaviorTest, SearchSourceBuilderFactoryTest, LuceneQuerySyntaxTest and others, 384 tests).

A managed index that is missing from the cluster is covered by the unit test only: deleting a shared index in the integration test cluster is not safe.

Not in this PR

  • /search/fieldQuery and /search/aggregate reach the engine through other code and still report an unknown index as a 500.
  • The UI's FAILED_TO_FIND_INDEX_ERROR constant has a typo (Failed to to find index), so the index-not-found banner never matches.

@manerow
manerow requested a review from a team as a code owner October 15, 2026 09:05
@manerow manerow added safe to test Add this label to run secure Github workflows on PRs backend labels Oct 15, 2026
@manerow
manerow requested a review from yan-3005 October 15, 2026 09:05
Comment on lines +20 to +22
* <p>A missing index ({@code 404}) depends on whose name it is. A name OpenMetadata does not manage
* is the caller's mistake and is a 400. A managed index that is missing from the cluster, for
* example after a failed reindex, is an outage and stays a 500. Issue #31878.

@gitar-bot gitar-bot Bot Oct 15, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Quality: New 400-vs-500 index-not-found contract has no decision record

This PR adds a REST error contract that clients and Collate both have to follow. /search/query and /search/get/{index}/doc/{id} now return 400 Unknown search index [<name as typed>] for a name OpenMetadata does not manage. A managed index that is missing from the cluster still returns 500 Failed to find index .... Nothing in docs/decisions/ records this rule.

The Javadoc in SearchEngineErrors covers the 400/500 split. It leaves out the parts of the rule that only appear in the PR description:

  • "Managed" covers Collate's indexes because they are "merged into the same registry". Collate has to keep registering its indexes there, or its own missing indexes will start returning 400 and stop alerting.
  • "Nothing is checked before the request reaches the engine, so no request that works today can start failing." This explains why the check is not done up front.
  • getDocByID keeps 404 Document not found. for a missing document, and a missing index there now follows the 400/500 split.

The repo squash-merges, so the description will not reach git log.

The record would say: "A search engine 404 for a missing index is reported as 400 Unknown search index [...] when any name in the expression is not an entity type, canonical index name or alias in the index-mapping registry (OSS plus Collate). Otherwise it stays a 500, because a missing managed index is an outage. Wildcards, exclusions and Data Insights names never count as unknown. Names are classified only after the engine has answered, never before the request is sent."

Add a record and cite it from the classifier.:

// docs/decisions/2026-10-<dd>-an-unknown-search-index-is-a-400-and-a-missing-managed-index-a-500.md
// and in SearchEngineErrors Javadoc:
 * ADR:2026-10-<dd>-an-unknown-search-index-is-a-400-and-a-missing-managed-index-a-500

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 0 closed / 1 findings

🟡 Medium risk · Reclassifying unknown-index failures as 400 across search and document endpoints could disrupt clients that rely on the previous 500 status.

Maps a search engine 404 for an unmanaged index name to a 400 Unknown search index [...] response, while missing managed indexes keep returning 500. Changes requested: the new 400-vs-500 index-not-found contract has no decision record in docs/decisions/. It should document that Collate's indexes must stay in the mapping registry, that classification happens only after the engine responds, and that getDocByID follows the same split.

⚠️ Quality: New 400-vs-500 index-not-found contract has no decision record

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/SearchEngineErrors.java:20-22 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/SearchEngineErrors.java:30-44 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/SearchIndexUtils.java:145-159 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java:594

This PR adds a REST error contract that clients and Collate both have to follow. /search/query and /search/get/{index}/doc/{id} now return 400 Unknown search index [<name as typed>] for a name OpenMetadata does not manage. A managed index that is missing from the cluster still returns 500 Failed to find index .... Nothing in docs/decisions/ records this rule.

The Javadoc in SearchEngineErrors covers the 400/500 split. It leaves out the parts of the rule that only appear in the PR description:

  • "Managed" covers Collate's indexes because they are "merged into the same registry". Collate has to keep registering its indexes there, or its own missing indexes will start returning 400 and stop alerting.
  • "Nothing is checked before the request reaches the engine, so no request that works today can start failing." This explains why the check is not done up front.
  • getDocByID keeps 404 Document not found. for a missing document, and a missing index there now follows the 400/500 split.

The repo squash-merges, so the description will not reach git log.

The record would say: "A search engine 404 for a missing index is reported as 400 Unknown search index [...] when any name in the expression is not an entity type, canonical index name or alias in the index-mapping registry (OSS plus Collate). Otherwise it stays a 500, because a missing managed index is an outage. Wildcards, exclusions and Data Insights names never count as unknown. Names are classified only after the engine has answered, never before the request is sent."

Add a record and cite it from the classifier.
// docs/decisions/2026-10-<dd>-an-unknown-search-index-is-a-400-and-a-missing-managed-index-a-500.md
// and in SearchEngineErrors Javadoc:
 * ADR:2026-10-<dd>-an-unknown-search-index-is-a-400-and-a-missing-managed-index-a-500
🤖 Prompt for agents
Code Review: Maps a search engine 404 for an unmanaged index name to a 400 `Unknown search index [...]` response, while missing managed indexes keep returning 500. Changes requested: the new 400-vs-500 index-not-found contract has no decision record in `docs/decisions/`. It should document that Collate's indexes must stay in the mapping registry, that classification happens only after the engine responds, and that `getDocByID` follows the same split.

1. ⚠️ Quality: New 400-vs-500 index-not-found contract has no decision record
   Files: openmetadata-service/src/main/java/org/openmetadata/service/search/SearchEngineErrors.java:20-22, openmetadata-service/src/main/java/org/openmetadata/service/search/SearchEngineErrors.java:30-44, openmetadata-service/src/main/java/org/openmetadata/service/search/SearchIndexUtils.java:145-159, openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java:594

   This PR adds a REST error contract that clients and Collate both have to follow. `/search/query` and `/search/get/{index}/doc/{id}` now return 400 `Unknown search index [<name as typed>]` for a name OpenMetadata does not manage. A managed index that is missing from the cluster still returns 500 `Failed to find index ...`. Nothing in `docs/decisions/` records this rule.
   
   The Javadoc in `SearchEngineErrors` covers the 400/500 split. It leaves out the parts of the rule that only appear in the PR description:
   - "Managed" covers Collate's indexes because they are "merged into the same registry". Collate has to keep registering its indexes there, or its own missing indexes will start returning 400 and stop alerting.
   - "Nothing is checked before the request reaches the engine, so no request that works today can start failing." This explains why the check is not done up front.
   - `getDocByID` keeps 404 `Document not found.` for a missing document, and a missing index there now follows the 400/500 split.
   
   The repo squash-merges, so the description will not reach `git log`.
   
   The record would say: *"A search engine 404 for a missing index is reported as 400 `Unknown search index [...]` when any name in the expression is not an entity type, canonical index name or alias in the index-mapping registry (OSS plus Collate). Otherwise it stays a 500, because a missing managed index is an outage. Wildcards, exclusions and Data Insights names never count as unknown. Names are classified only after the engine has answered, never before the request is sent."*

   Fix (Add a record and cite it from the classifier.):
   // docs/decisions/2026-10-<dd>-an-unknown-search-index-is-a-400-and-a-missing-managed-index-a-500.md
   // and in SearchEngineErrors Javadoc:
    * ADR:2026-10-<dd>-an-unknown-search-index-is-a-400-and-a-missing-managed-index-a-500

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

Copy link
Copy Markdown

@manerow
manerow added this pull request to the merge queue Oct 15, 2026
Merged via the queue into main with commit 15e1475 Oct 16, 2026
127 of 128 checks passed
@manerow
manerow deleted the fix/31878-unknown-index-400 branch October 16, 2026 05:21
manerow added a commit that referenced this pull request Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

search/query returns 500 for a malformed user query; a client input error should be 400

2 participants