Repository navigation
fix(search): drop flattened/flat_object highlight fields before query - #28674
mohityadav766 wants to merge 12 commits into
Conversation
When SearchSettings has a highlight field that targets a flattened mapping subfield (e.g. `extension.foundry_rid` from a custom property, or `columns.children.*`), both factories were forwarding it straight to the search engine. flat_object/flattened subfields have no analyzer, so the highlight phase fails at the shard level with "Field [...] has no associated analyzer", which surfaces as `all shards failed` and breaks every workflow that runs the affected query (e.g. Automator over the container index). Reindexing does not fix this — the bad config lives in Search Settings. Filter highlight fields against the known set of flattened paths (`extension`, `columns.extension`, `columns.children`, `dataModel.columns.*`, schema-field `children` paths) in both the OpenSearch and Elasticsearch source builder factories before adding them to the highlight clause. Misconfigured fields are silently dropped and logged at DEBUG; the search query stays valid and the customer no longer needs to manually toggle Highlight Fields off to unblock. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This pull request hardens the search highlight builder so misconfigured highlight fields that target flattened (Elasticsearch) / flat_object (OpenSearch) mapped paths are dropped before query execution, preventing shard-level highlight failures that surface as all shards failed (500) from /v1/search/query.
Changes:
- Centralizes known flattened field roots in
SearchSourceBuilderFactoryand adds a classifier + filter to exclude highlight-unsafe paths. - Applies highlight-field sanitization in both OpenSearch and Elasticsearch highlight builders (V2).
- Adds regression tests covering asset-specific highlight config, global fallback highlight config, and the classifier contract.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| openmetadata-service/src/main/java/org/openmetadata/service/search/SearchSourceBuilderFactory.java | Adds a centralized set of flattened roots plus helper methods to classify/filter highlight fields. |
| openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSourceBuilderFactory.java | Filters configured highlight fields to drop flat_object/flattened subfields before building the highlight clause. |
| openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSourceBuilderFactory.java | Filters configured highlight fields to drop flattened subfields before building the highlight clause. |
| openmetadata-service/src/test/java/org/openmetadata/service/search/SearchSourceBuilderFactoryTest.java | Adds regression tests ensuring unsafe highlight paths are dropped for both factories and via global fallback. |
🔴 Playwright Results — 4 failure(s), 18 flaky✅ 4479 passed · ❌ 4 failed · 🟡 18 flaky · ⏭️ 38 skipped
Genuine Failures (failed on all attempts)❌
|
…t path Address PR review on highlight flattened-field filtering: - filterHighlightSafeFields returns the original list when no field is unsafe, avoiding an allocation/copy on the /v1/search/query hot path - guard the "dropping highlight fields" debug log in both the ES and OS buildHighlightsV2 with LOG.isDebugEnabled() so the stream is not materialized when DEBUG is disabled Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Addresses the gitar-bot review finding on #28674: the hot-path optimization made filterHighlightSafeFields return null for null input (it previously always returned a non-null list), which both buildHighlightsV2 for-loops would NPE on. Not reachable today (all callers null-guard), but it breaks the documented "returns a list" contract. Return List.of() for null — preserves null-safety with no extra allocation on the fast path. Adds a test pinning the null / fast-path-identity / drop contract. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
| public static void removeUnsupportedHighlightFields() { | ||
| try { | ||
| Settings stored = SearchSettingsMergeUtil.getSearchSettingsFromDatabase(); | ||
| SearchSettings defaults = SearchSettingsMergeUtil.loadSearchSettingsFromFile(); | ||
| if (stored == null || defaults == null) { | ||
| LOG.warn("Search settings not available; skipping highlight-field cleanup"); | ||
| } else { | ||
| SearchSettings settings = SearchSettingsMergeUtil.loadSearchSettings(stored); | ||
| if (removeDisallowedHighlightFields(settings, highlightableFields(defaults))) { | ||
| SearchSettingsMergeUtil.saveSearchSettings(stored, settings); | ||
| LOG.info("Removed unsupported highlight fields from stored search settings"); | ||
| } else { | ||
| LOG.info("No unsupported highlight fields found in stored search settings"); | ||
| } | ||
| } |
There was a problem hiding this comment.
💡 Edge Case: Migration swallows exceptions, permanently skipping highlight cleanup
removeUnsupportedHighlightFields() wraps its entire body in a try/catch that only logs the exception and returns normally (MigrationUtil.java:53-55). Because runDataMigration() (mysql/postgres v11211 Migration.java) then completes without throwing, the migration framework records 1.12.11 as successfully applied. If the DB read (getSearchSettingsFromDatabase) or loadSearchSettings fails transiently during startup — e.g. a slow/unavailable connection, or invalid JSON that loadSearchSettings throws on — the cleanup is silently skipped and will never be retried on subsequent startups. The stored SearchSettings then retain the invalid flattened highlight fields, and the customer-facing 500 (all shards failed / has no associated analyzer) that this PR is meant to fix persists with no operator-visible signal beyond a single ERROR log line.
Consider letting the exception propagate (remove the catch, or rethrow) so the migration is marked failed and retried, or at minimum raise the log to a level/alert that clearly flags the fix did not apply. Given there is no runtime guard in the query path in this PR, a silently-skipped migration means the bug is not fixed for that deployment.
Let exceptions propagate so a failed migration is not silently marked complete and is retried on the next startup.:
public static void removeUnsupportedHighlightFields() {
Settings stored = SearchSettingsMergeUtil.getSearchSettingsFromDatabase();
SearchSettings defaults = SearchSettingsMergeUtil.loadSearchSettingsFromFile();
if (stored == null || defaults == null) {
LOG.warn("Search settings not available; skipping highlight-field cleanup");
return;
}
SearchSettings settings = SearchSettingsMergeUtil.loadSearchSettings(stored);
if (removeDisallowedHighlightFields(settings, highlightableFields(defaults))) {
SearchSettingsMergeUtil.saveSearchSettings(stored, settings);
LOG.info("Removed unsupported highlight fields from stored search settings");
} else {
LOG.info("No unsupported highlight fields found in stored search settings");
}
}
Was this helpful? React with 👍 / 👎
| checked={ | ||
| searchSettings?.highlightFields?.includes(field.fieldName) ?? | ||
| false | ||
| isHighlightAllowed && | ||
| (searchSettings?.highlightFields?.includes(field.fieldName) ?? | ||
| false) | ||
| } |
| static Set<String> highlightableFields(SearchSettings settings) { | ||
| Set<String> names = new HashSet<>(); | ||
| if (settings != null && settings.getAllowedFields() != null) { | ||
| for (AllowedSearchFields allowed : settings.getAllowedFields()) { | ||
| collectHighlightable(allowed.getFields(), names); |
| Set<String> highlightable = | ||
| defaultSearchSettings.getAllowedFields().stream() | ||
| .flatMap(allowed -> allowed.getFields().stream()) | ||
| .filter(field -> Boolean.TRUE.equals(field.getHighlight())) | ||
| .map(Field::getName) |
| * Drop highlight fields that the search settings configuration does not mark as highlightable. | ||
| * Only fields flagged {@code "highlight": true} in {@code allowedFields} (analyzed text fields) | ||
| * can be highlighted; flattened/flat_object and non-indexed fields previously saved as highlight | ||
| * fields make the highlight phase fail (500) at query time. The allow-list comes from the shipped | ||
| * default settings (the source of truth for the flag); the stored highlightFields are filtered |
Code Review 👍 Approved with suggestions 4 resolved / 5 findingsAdds a validation schema for searchable fields and a migration to strip unsupported highlight configurations, addressing the 500-error caused by flattened mapping fields. Consider refining the migration error handling to avoid silent failures if the cleanup process encounters connectivity issues. 💡 Edge Case: Migration swallows exceptions, permanently skipping highlight cleanup📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v11211/MigrationUtil.java:38-52 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/mysql/v11211/Migration.java:28-32
Consider letting the exception propagate (remove the catch, or rethrow) so the migration is marked failed and retried, or at minimum raise the log to a level/alert that clearly flags the fix did not apply. Given there is no runtime guard in the query path in this PR, a silently-skipped migration means the bug is not fixed for that deployment. Let exceptions propagate so a failed migration is not silently marked complete and is retried on the next startup.✅ 4 resolved✅ Edge Case: filterHighlightSafeFields now returns null for null input
✅ Bug: Migration drops valid highlight fields columns.name/columns.description
✅ Edge Case: Highlight toggle disabled for all fields while entityFields loads
✅ Edge Case: Migration strips custom highlightable fields not present in defaults
🤖 Prompt for agentsOptionsDisplay: compact → Showing less information. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
|



Summary
When SearchSettings has a highlight field that targets a
flattened(Elasticsearch) /
flat_object(OpenSearch) mapping subfield — mostcommonly a custom property under
extension.*, but alsocolumns.children.*,columns.extension.*,dataModel.columns.*, or schema-fieldchildrenpaths— the search source builders were forwarding it straight into the highlight
clause.
Subfields of those mappings are stored as raw keywords with no
analyzer, so the highlight phase fails at the shard level with
Field [...] has no associated analyzer. That surfaces to the calleras
all shards failed, returns a 500 from/v1/search/query, andbreaks every workflow that runs the affected query (e.g. Automator
matching containers). Reindexing does not fix this — the bad config
lives in Search Settings, not in the index.
The customer-visible exception:
This change adds a single source of truth for the set of flattened
field paths on
SearchSourceBuilderFactoryand filters configuredhighlight fields against it in both
OpenSearchSourceBuilderFactory.buildHighlightsV2and
ElasticSearchSourceBuilderFactory.buildHighlightsV2. Droppedfields are logged at DEBUG. The query stays valid and the customer no
longer needs to manually toggle Highlight Fields off to unblock.
The audit covered every index mapping under
openmetadata-spec/src/main/resources/elasticsearch/. The full set offlattened paths now centralized:
extensioncolumns.extension,columns.childrendataModel.columns.extension,dataModel.columns.childrenfields.childrenmessageSchema.schemaFields.childrenrequestSchema.schemaFields.children,responseSchema.schemaFields.childrenIf a new flattened field is added to any mapping in the future, add
its dotted path to
FLATTENED_FIELD_PATHSto keep highlight safe.Files changed
openmetadata-service/.../search/SearchSourceBuilderFactory.java— newFLATTENED_FIELD_PATHSset,isHighlightUnsafeField,filterHighlightSafeFieldsopenmetadata-service/.../search/opensearch/OpenSearchSourceBuilderFactory.java— sanitize highlight fields inbuildHighlightsV2openmetadata-service/.../search/elasticsearch/ElasticSearchSourceBuilderFactory.java— sanitize highlight fields inbuildHighlightsV2openmetadata-service/.../search/SearchSourceBuilderFactoryTest.java— three new regression testsTest plan
mvn -pl openmetadata-service test -Dtest=SearchSourceBuilderFactoryTest— 15/15 pass (3 new tests fail without the fix)mvn -pl openmetadata-service spotless:check— cleanassetConfig.highlightFieldsare droppedglobalSettings.highlightFields(fallback path) are droppedisHighlightUnsafeField) pins behaviour for known roots, dotted subfields, lookalikes likeextensionLabel, and null/emptyFollow-up (out of scope for this PR)
Save-time validation in
SearchSettingsResourcethat warns / rejectshighlight fields targeting flattened paths, so misconfig is caught at
config time rather than relying on the runtime guard. The runtime guard
in this PR fully unblocks the customer; the save-time check is a
separate, larger change that touches the UI affordance as well.
🤖 Generated with Claude Code
Summary by Gitar
highlightboolean toFieldschema insearchSettings.jsonto identify highlightable fields.v11211data migration to clean up invalid highlight fields from existingSearchSettingsby referencing thehighlight: trueflag in defaults.isHighlightAllowedlogic toFieldConfigurationto disable the highlight toggle for unsupported fields.searchSettings.jsonto mark standard text fields (e.g.,name,description) as eligible for highlighting ("highlight": true).MigrationUtilTestandSearchSettingsHandlerTestto verify that invalid highlight fields are correctly identified and stripped during migration.This will update automatically on new commits.
Greptile Summary
This PR addresses search failures caused by highlighting configured on
flattened/flat_objectorenabled:falsemapping fields (e.g.,extension.*,columns.children.*). These fields have no associated analyzer, causingall shards failed500s when the highlight phase runs.highlightboolean to theFieldschema insearchSettings.jsonso eachallowedFieldsentry explicitly declares whether its underlying mapping is a highlightable (analyzed) text field, providing the UI with a static allow-list.SearchSettings, strips anyhighlightFieldsentries not markedhighlight: truein the defaults, and writes the cleaned settings back—removing misconfigurations without requiring a reindex.FieldConfiguration.tsxto disable the highlight toggle for any field whoseallowedFieldsentry lackshighlight: true, preventing future misconfigurations via the UI.Confidence Score: 4/5
Safe to merge with awareness: the migration cleans up stored highlight settings and the UI guard prevents future misconfigurations, but if the migration fails silently the next search query on an affected entity will still return a 500 until settings are manually corrected.
The migration-only approach means the system's correctness entirely depends on the migration completing successfully. If
getSearchSettingsFromDatabase()orsaveSearchSettings()fail, the exception is caught and logged but the broken configuration remains. The remainder of the change — schema additions,highlight: trueannotations across ~60 fields verified against actual index mappings, and the UI disable logic — is accurate and well-tested.openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v11211/MigrationUtil.java — the silent exception swallow on lines 53-55 and the global-set approach on lines 58-66 are the main areas to scrutinise before merging.
Important Files Changed
removeIfto strip disallowed highlight entries from stored settings. Two previously-flagged concerns remain: the global (cross-entity) allowlist and silent exception swallowing; the in-placeremoveIfassumes a mutable list from Jackson deserialization, which holds in practice.highlight: trueto ~60 analyzed text fields across all entity types. Verified against index mappings: all flagged fields (name,displayName,description,path,extractedText,dataModel.columns.*, etc.) are backed byom_analyzertext mappings; flattened/disabled fields are deliberately excluded.highlightboolean property (default false) to theFieldschema definition. Schema change is backward-compatible; existing stored settings without the flag default tofalse.highlightflag fromentityFieldConfigto deriveisHighlightAllowed; disables the switch and short-circuitscheckedtofalsefor disallowed fields. A previously-flagged concern: whenisHighlightAllowedis false the switch always shows OFF, hiding the stored state if migration silently failed.everyDefaultHighlightFieldIsMarkedHighlightableInAllowedFieldsverifies that every field in the defaulthighlightFieldslists has a correspondingallowedFieldsentry withhighlight: true, acting as a compile-time guard against future drift between the two config sections.new ArrayList<>()wrappers ensuringremoveIfmutability assumptions are satisfied in tests.MigrationUtil.removeUnsupportedHighlightFields().onHighlightFieldsChangeis not called whenentityFieldslackshighlight: truefor the current field.Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant DB as Database participant MU as MigrationUtil (v11211) participant SMU as SearchSettingsMergeUtil participant UI as FieldConfiguration (UI) participant ES as Elasticsearch/OpenSearch Note over MU: Migration runs on upgrade to 1.12.11 MU->>SMU: getSearchSettingsFromDatabase() SMU-->>MU: stored Settings MU->>SMU: loadSearchSettingsFromFile() SMU-->>MU: defaults SearchSettings MU->>MU: highlightableFields(defaults) builds global Set MU->>MU: removeDisallowedHighlightFields via removeIf alt Any fields removed MU->>SMU: saveSearchSettings(stored, settings) SMU->>DB: persist cleaned settings Note over DB: extension.*, columns.children.* removed end Note over UI: User opens Search Settings UI->>UI: "isHighlightAllowed = entityFieldConfig?.highlight ?? false" UI->>UI: Switch disabled when isHighlightAllowed is false Note over ES: Query time after migration ES->>ES: highlightFields no longer contain flattened paths ES-->>ES: Highlight phase succeeds%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant DB as Database participant MU as MigrationUtil (v11211) participant SMU as SearchSettingsMergeUtil participant UI as FieldConfiguration (UI) participant ES as Elasticsearch/OpenSearch Note over MU: Migration runs on upgrade to 1.12.11 MU->>SMU: getSearchSettingsFromDatabase() SMU-->>MU: stored Settings MU->>SMU: loadSearchSettingsFromFile() SMU-->>MU: defaults SearchSettings MU->>MU: highlightableFields(defaults) builds global Set MU->>MU: removeDisallowedHighlightFields via removeIf alt Any fields removed MU->>SMU: saveSearchSettings(stored, settings) SMU->>DB: persist cleaned settings Note over DB: extension.*, columns.children.* removed end Note over UI: User opens Search Settings UI->>UI: "isHighlightAllowed = entityFieldConfig?.highlight ?? false" UI->>UI: Switch disabled when isHighlightAllowed is false Note over ES: Query time after migration ES->>ES: highlightFields no longer contain flattened paths ES-->>ES: Highlight phase succeedsReviews (3): Last reviewed commit: "Merge branch 'main' into fix-highlight-f..." | Re-trigger Greptile