Skip to content

Fixes #32656: correct topic/apiEndpoint fieldNames aggregation field and align APIEndpoint writer to mapping - #32724

Merged
mohityadav766 merged 2 commits into
mainfrom
detail/bug-fix/fixes-32656-correct-topic-apiendpoint-fieldnames-a-1c2a0c
Sep 16, 2026
Merged

mohityadav766 merged 2 commits into
mainfrom
detail/bug-fix/fixes-32656-correct-topic-apiendpoint-fieldnames-a-1c2a0c

Conversation

@detail-app

@detail-app detail-app Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Detail bug report: View on Detail

Describe your changes:

Fixes #32656

I worked on the silent fieldNames aggregation misconfiguration in searchSettings.json because the topic and apiEndpoint asset configs declared a terms aggregation against "field": "fieldsNames" (an extra s), a field that exists in no Elasticsearch/OpenSearch mapping and no Java writer. Terms aggregations on an unmapped field return no buckets without raising an error, so /v1/search/query silently emitted fieldNames: { "buckets": [] } for every topic/apiEndpoint search. The apiEndpoint side additionally had a writer/mapping mismatch: APIEndpointIndex wrote request_field_names/response_field_names (snake_case) while api_endpoint_index_mapping.json declared requestFieldNames/responseFieldNames (camelCase) keyword fields that were never populated.

Type of change:

  • Bug fix

High-level design:

  • searchSettings.json — corrected the topic aggregation to "field": "fieldNames" (the mapped keyword array TopicIndex already writes). Replaced the single broken apiEndpoint fieldNames aggregation with two aggregations, requestFieldNames and responseFieldNames, pointing at the mapped camelCase keyword fields.
  • APIEndpointIndex.java — aligns the writer to the mapping: it now puts requestFieldNames/responseFieldNames (camelCase keyword, matching api_endpoint_index_mapping.json). The *_field_namesFuzzy text fields used for search relevance are unchanged, so the boosted ranking channel is untouched.
  • v210 migration — SearchSettingsHandler#mergeAssetTypeConfigurations only adds missing asset types and never re-merges per-asset aggregations, so correcting the seed alone leaves upgraded clusters pointing at the stale field. Added SearchAggregationFieldRepair (idempotent; precedent: v1132 fixOwnerDisplayNameAggregation, v202 SearchNameKeywordRepair) and hooked it into the existing in-development v210 Migration.runDataMigration() for both mysql and postgres. It retargets the topic fieldNames field to fieldNames and replaces the apiEndpoint fieldNames aggregation with requestFieldNames + responseFieldNames from the seed.
  • Regression guard — added SearchSettingsHandlerTest.everyConfiguredAggregationFieldExistsInItsIndexMapping, which resolves each configured aggregation field via SearchSourceBuilderFactory.resolveFieldForSortOrAggregation and asserts it names a real path in that asset's index mapping (descending both properties and .keyword multi-fields). Two same-class pre-existing misconfigurations the guard surfaced (query|queryType, glossaryTerm|status) are excluded via a self-maintaining pendingMappingFix allowlist that also fails if an entry becomes stale, so removing a fixed one is enforced. This is the durable guard the issue recommends; it catches the original typo if reintroduced.

Tests:

Use cases covered

  • Topic fieldNames aggregation returns populated buckets (incl. flattened nested child field names) from the mapped keyword array the writer produces.
  • apiEndpoint requestFieldNames/responseFieldNames aggregations return populated buckets from the mapped camelCase keyword fields after the writer is aligned; the old fieldNames aggregation key is gone.
  • The existing UI schema-field facets (messageSchema.schemaFields.name.keyword, requestSchema.schemaFields.name.keyword, responseSchema.schemaFields.name.keyword) still return buckets — no regression.
  • The fieldNamesFuzzy / *_field_namesFuzzy search-relevance channel is unchanged.
  • Upgraded clusters carrying the stale fieldsNames aggregation are repaired by the v210 migration, and a second migration pass makes no further change (idempotent).
  • Any future aggregation field that references an unmapped path fails the new unit guard.

Unit tests

  • I added unit tests for the new/changed logic.
  • Files added/updated:
    • openmetadata-service/.../resources/system/SearchSettingsHandlerTest.java — new everyConfiguredAggregationFieldExistsInItsIndexMapping + everyGlobalAggregationFieldExistsInAtLeastOneIndexMapping guards.
    • openmetadata-service/.../migration/utils/v210/SearchAggregationFieldRepairTest.java — 8 cases: retarget topic, split apiEndpoint, idempotency, leave-correct-topic-alone, no-duplicate, added-when-stale-removed, empty settings, missing-asset-types.
    • openmetadata-service/.../search/indexes/EntitySpecificFieldsTest.java — assertions updated for the requestFieldNames/responseFieldNames writer rename.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for new/changed API endpoints.
  • Files added/updated:
    • openmetadata-integration-tests/.../tests/search/FieldNamesAggregationIT.java — indexes a real topic and apiEndpoint doc (carrying the writer's exact output) into the shipped en mappings in an OpenSearch container and asserts the fieldNames/requestFieldNames/responseFieldNames/messageSchema.schemaFields.name.keyword/requestSchema.schemaFields.name.keyword/responseSchema.schemaFields.name.keyword aggregations return the expected buckets, plus a negative control asserting the misspelled fieldsNames aggregation returns no buckets (reproducing the original silent failure).

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes; no first-party UI consumer reads the fieldNames aggregation key — the schema-field facets are served by the correct first aggregation in each config, which is untouched).

Manual testing performed

  • Verified the new unit guard fails-as-expected when the topic fieldsNames typo is reintroduced, and restores green after revert.
  • Verified the pendingMappingFix allowlist is self-maintaining in both directions: removing an entry while its field is still unmapped fails the enforcement assertion; keeping an entry after its field is retargeted to a mapped field fails the stale-allowlist assertion.
  • Ran the existing search integration suite (Testcontainers + MySQL + OpenSearch): SearchConsumerFieldBehaviorIT (20), HighlightFieldSaveValidationIT (4), LiveSearchSettingsChangeIT (1), PerEntitySearchDefaultsIT (1), CustomPropertyAggregationIT (2), and the new FieldNamesAggregationIT (5) — all pass.
  • Confirmed a DB round-trip of the v210 repair against a live embedded cluster (seed stale fieldsNames via the save path, run the repair, GET settings back) repairs the stored aggregations and is idempotent on a second pass (covered by the migration unit test's idempotency case).

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed. (N/A — no JSON Schema changes; the v210 data migration for the stored searchSettings is included.)
  • For UI changes: I attached a screen recording and/or screenshots above. (N/A)
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

Bug fix

  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.

Automatic Fixes PRs can be configured here.

Greptile Summary

This PR aligns topic and apiEndpoint field-name aggregations with their index mappings, changes the apiEndpoint index writer to populate mapped camelCase keyword fields, and adds a v210 stored-settings repair plus regression tests.

  • Corrects the topic aggregation target and splits apiEndpoint field-name aggregations by request and response.
  • Adds MySQL and PostgreSQL v210 migration hooks for existing stored search settings.
  • Adds mapping validation, migration unit coverage, and an OpenSearch integration reproduction.
  • Upgrade handling still needs to account for pre-existing indexed documents and avoid deleting valid customized aggregations.
Confidence Score: 3/5

The PR is not yet safe to merge because upgraded installations can retain empty apiEndpoint field-name buckets and the migration can delete valid customized aggregations.

The settings migration changes aggregation targets without rewriting existing documents, while its name-only removal predicate destructively treats every customized fieldNames aggregation as stale; two explicit Java conventions also remain unsatisfied.

Files Needing Attention: openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/SearchAggregationFieldRepair.java, openmetadata-service/src/main/java/org/openmetadata/service/migration/mysql/v210/Migration.java, openmetadata-service/src/main/java/org/openmetadata/service/migration/postgres/v210/Migration.java, openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/search/FieldNamesAggregationIT.java

Important Files Changed
Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/SearchAggregationFieldRepair.java Adds the stored-settings repair, but removes customized fieldNames aggregations too broadly and violates the specific-exception rule.
openmetadata-service/src/main/java/org/openmetadata/service/migration/mysql/v210/Migration.java Hooks the repair into MySQL upgrades without arranging for existing apiEndpoint search documents to be rewritten.
openmetadata-service/src/main/java/org/openmetadata/service/migration/postgres/v210/Migration.java Hooks the same settings-only repair into PostgreSQL upgrades.
openmetadata-service/src/main/java/org/openmetadata/service/search/indexes/APIEndpointIndex.java Correctly aligns newly written exact field-name arrays with the mapped camelCase keyword fields, but existing documents require reindexing.
openmetadata-service/src/main/resources/json/data/settings/searchSettings.json Corrects the topic target and introduces mapped request/response apiEndpoint aggregation fields.
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/search/FieldNamesAggregationIT.java Verifies aggregation behavior against shipped mappings, with one Java import-style violation.
openmetadata-service/src/test/java/org/openmetadata/service/resources/system/SearchSettingsHandlerTest.java Adds durable validation that configured aggregation fields resolve to mapped paths.
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  U[Upgrade to v210] --> M[Repair stored aggregation settings]
  M --> A[Aggregations target camelCase fields]
  D[Existing apiEndpoint documents] --> O[snake_case exact fields only]
  A --> E[Empty buckets for unchanged documents]
  O --> E
  R[Manual reindex or entity update] --> W[APIEndpointIndex rewrites document]
  W --> N[camelCase keyword fields populated]
  N --> B[Populated request/response buckets]
Loading

Reviews (1): Last reviewed commit: "Merge branch 'main' into detail/bug-fix/..." | Re-trigger Greptile

Greptile also left 4 inline comments on this PR.

Context used:

  • Context used - CLAUDE.md (source)

@detail-app
detail-app Bot requested a review from a team as a code owner September 6, 2026 06:32
@detail-app
detail-app Bot requested a review from harshach September 6, 2026 06:32
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 8a8a883c6ad6aaa884398a921101b372cabdc8df in Playwright run 35111234138, attempt 1.

✅ 4501 passed · ❌ 0 failed · 🟡 9 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 50m 29s

⏱️ Max setup 4m 31s · max shard execution 19m 46s · max shard-job elapsed before upload 23m 1s · reporting 22s

🌐 219.22 requests/attempt · 2.23 app boots/UI scenario · 42.16% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 42.16% (convergence target: at most 15%).
  • Browser traffic was 219.22 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.23 per UI scenario (10693 boots / 4799 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard advanced-search-01 66 0 0 0 0 0
✅ Shard advanced-search-02 64 0 0 0 0 0
✅ Shard chromium-01 146 0 0 0 0 0
✅ Shard chromium-02 173 0 0 0 0 0
🟡 Shard chromium-03 160 0 1 0 0 0
🟡 Shard chromium-04 159 0 1 0 0 0
✅ Shard chromium-05 145 0 0 0 0 0
✅ Shard chromium-06 147 0 0 0 0 0
🟡 Shard chromium-07 119 0 1 0 0 0
✅ Shard chromium-08 174 0 0 0 0 0
✅ Shard chromium-09 172 0 0 0 0 0
✅ Shard chromium-10 162 0 0 0 0 0
✅ Shard chromium-11 130 0 0 0 0 0
✅ Shard chromium-12 149 0 0 0 0 0
✅ Shard chromium-13 162 0 0 0 0 0
✅ Shard chromium-14 177 0 0 0 0 0
✅ Shard chromium-15 127 0 0 1 0 0
🟡 Shard chromium-16 204 0 1 0 0 0
🟡 Shard chromium-17 167 0 1 0 0 0
🟡 Shard chromium-18 159 0 1 0 0 0
✅ Shard chromium-19 143 0 0 0 0 0
✅ Shard chromium-20 152 0 0 0 0 0
✅ Shard chromium-21 142 0 0 0 0 0
🟡 Shard chromium-22 161 0 1 0 0 0
🟡 Shard chromium-23 168 0 1 0 0 0
✅ Shard chromium-24 206 0 0 0 0 0
🟡 Shard chromium-25 138 0 1 0 0 0
✅ Shard data-asset-rules-01 65 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard import-export-01 76 0 0 0 0 0
✅ Shard import-export-02 74 0 0 0 0 0
✅ Shard ingestion-01 38 0 0 0 0 0
✅ Shard ingestion-02 57 0 0 0 0 0
✅ Shard reindex-01 28 0 0 0 0 0
✅ Shard search-01 12 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 9 flaky test(s) (passed on retry)
  • Pages/Users.spec.ts › Admin soft & hard delete and restore user from profile page (shard chromium-03, 1 retry)
  • Features/AIMode/CustomPropertiesPanel.spec.ts › adds an Entity Reference List custom property (shard chromium-04, 1 retry)
  • Features/Permissions/EntityPermissions.spec.ts › Topic allow common operations permissions (shard chromium-07, 1 retry)
  • Pages/ServiceEntity.spec.ts › Delete Database Service (shard chromium-16, 1 retry)
  • Pages/CustomProperties.spec.ts › Entity Reference CP with all operators (shard chromium-17, 1 retry)
  • Flow/PersonaFlow.spec.ts › Set and remove default persona should work properly (shard chromium-18, 1 retry)
  • Pages/DataInsightReportApplication.spec.ts › Run application (shard chromium-22, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard chromium-23, 1 retry)
  • Pages/Glossary.spec.ts › Rename Glossary Term and verify assets (shard chromium-25, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

mohityadav766
mohityadav766 previously approved these changes Sep 16, 2026
// aggregations are not re-merged), so existing installs only get the fix through this
// migration.
// Idempotent.
repairFieldNamesAggregations();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Existing documents remain stale

On a normal v210 upgrade, the MySQL and PostgreSQL migrations retarget the stored aggregations to requestFieldNames and responseFieldNames, but they do not reindex existing apiEndpoint documents. Those documents retain the old snake_case fields, so unchanged endpoints continue returning empty field-name buckets until an operator runs the separate reindex command or the entity is updated.

List<Aggregation> aggregations = apiEndpoint.getAggregations();
// The apiEndpoint index mapping has no `fieldNames` field (it has `requestFieldNames` and
// `responseFieldNames`), so any `fieldNames` aggregation here is the stale misconfiguration.
boolean removed = aggregations.removeIf(agg -> FIELD_NAMES_AGG_NAME.equals(agg.getName()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Valid custom aggregations deleted

This removes every apiEndpoint aggregation named fieldNames, rather than only the stale aggregation whose field is fieldsNames. Existing per-asset settings may contain persisted customizations, so an upgrade can silently delete a valid compatibility aggregation such as fieldNames targeting requestFieldNames. Restrict removal to the known stale name-and-field combination.

List<String> responseKeys =
bucketKeys(
"api_endpoint_agg_en",
termsAggregation("respSchemaFields", "responseSchema.schemaFields.name.keyword"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Fully qualified class name

The new test instantiates java.util.ArrayList with a fully qualified class name. The repository's Java conventions require importing the class instead, so this requirement must be satisfied before merging.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

LOG.info(
"No stale fieldNames aggregation found in stored search settings; no repair needed");
}
} catch (Exception e) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Broad exception catch

The new migration catches the broad Exception type. The repository's Java conventions prohibit catch (Exception e) and require catching the specific database, parsing, and resource-loading exception types, so this requirement must be satisfied before merging.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@mohityadav766
mohityadav766 added this pull request to the merge queue Sep 16, 2026
Merged via the queue into main with commit a7a8cbc Sep 16, 2026
161 of 162 checks passed
@mohityadav766
mohityadav766 deleted the detail/bug-fix/fixes-32656-correct-topic-apiendpoint-fieldnames-a-1c2a0c branch September 16, 2026 16:37
mohityadav766 added a commit that referenced this pull request Nov 17, 2026
…37994)

2.0's APIEndpointIndex writes an endpoint's response fields under
response_field_names. The camel-case responseFieldNames key came with
#32724 on main (writer aligned to the mapping, with a 2.1 migration),
which 2.0 does not have. The backported test waited on the main-only key
and timed out on every engine.

This branch was previously deployed

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

Labels

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.

[Detail Bug] Search API: Topic and APIEndpoint fieldNames aggregation always empty due to misconfigured aggregation field

2 participants