Repository navigation
Fixes #38379: escape Lucene regexp metacharacters in search aggregate include patterns - #38414
Merged
TeddyCr merged 5 commits intoNov 26, 2026
Conversation
… include patterns
Appending .* for the prefix sub-agg lets child tags (e.g. pii.a.child) displace requested siblings (e.g. pii.b) under the best-match merge limit, producing false-zero bucket counts. Use the caller's pattern verbatim for exact/prefix/contains in the pre-built regexp path. Also drop the anchored (^…$) pre-built regexp test: ^ and $ are anchors in Java Pattern but literal in Lucene, so the test promised anchor behavior that does not hold in production.
…exp-metacharacters-in-f24b99
Contributor
UI browser testsRan: all test files (no impact map from main yet) Result: ✅ 1094 passed · 154 skipped Changed code executed by these browser tests: 2 / 2 lines (100%)
|
…exp-metacharacters-in-f24b99
TeddyCr
approved these changes
Nov 25, 2026
TeddyCr
enabled auto-merge (squash)
November 25, 2026 22:46
chirag-madlani
approved these changes
Nov 26, 2026
TeddyCr
deleted the
detail/bug-fix/fixes-38379-escape-lucene-regexp-metacharacters-in-f24b99
branch
November 26, 2026 06:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Detail bug report: View on Detail
Describe your changes:
Fixes #38379
I worked on fixing a server-side Lucene regexp escaping gap in the
/v1/search/aggregatequick-filter path because direct REST consumers that sent afieldValuecontaining metacharacters OpenMetadata itself permits in tag/glossary/owner/service names (Pii.Phone (mobile),R&D Team,C++,A|B, trailing\) either got an HTTP 500 for the whole aggregation request or silently wrong counts.Type of change:
High-level design:
N/A — small change.
Tests:
Use cases covered
.*Pii.Phone (mobile).*→ HTTP 200 with the literal bucketpii.phone (mobile)(previously:(mobile)was a Lucene group → 0 buckets)..*C++.*→ matches only thec++bucket, notc/cc/ccc(previously:++quantifier over-matched)..*R&D Team.*→ matches ther&d teambucket (previously:&intersection operator → empty automaton → 0 buckets).(pii\.a|pii\.b)posted viapostExactAggregateFieldOptions(theuseTagUsageCountspath) still match either FQN — they pass through verbatim, the server does NOT escape their(|)operators.Unit tests
SearchUtils.escapeLuceneRegexp+SearchUtils.buildBestMatchIncludePatternshelpers and unit tests inopenmetadata-service/src/test/java/org/openmetadata/service/search/SearchUtilsTest.javacovering: every Lucene regexp metacharacter (compile + literal-match + no-overmatch), the trailing-\request-rejection case, the literal quick-filter path (full escaping for exact/prefix/contains), pre-built alternation pass-through, and dot-only-input preservation.openmetadata-ui/src/main/resources/ui/src/rest/miscAPI.test.tspinning thatgetAggregateFieldOptions/postAggregateFieldOptionssend.*value.*raw (no client-side backslash escaping) forC++,R&D Team,A|B,Revenue (net of tax) [US],john?,user.id, and.*for empty value.Backend integration tests
SearchAggregateRbacIT.test_aggregate_fieldValueWithRegexpMetacharactersMatchesLiteralTerminopenmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/search/SearchAggregateRbacIT.java. It seeds glossary terms with metacharacter-bearing display names and POSTsfieldValuecontaining parens,&,++, and[], asserting HTTP 200 (the SDK client throws on non-2xx) and that each bucket key is the literal term — not a group, intersection, or quantifier result.PR checks run only the Java unit tests; the integration tests run in the merge queue and JavaUIIT / search-it nightly. Ran the impacted integration tests locally for both engines (see Manual testing).
Ingestion integration tests
Playwright (UI) tests
Manual testing performed
SearchAggregateRbacITagainst Testcontainers Elasticsearch (-Pmysql-elasticsearch) — 8/8 pass (7 original + the new metacharacter test). Same against OpenSearch (-Ppostgres-opensearch) — 7/7 pass.searcharea of.github/java-tests/impact-map.jsonfor both engines —FieldNamesAggregationIT(5/5),CustomPropertyAggregationIT(2/2),TableTotalCountAggregationIT(1/1) on each engine./v1/search/aggregatewith the UI's exact request shape:fieldValue: ".*pii.phone (mobile).*"→ HTTP 200, bucketpii.phone (mobile)(doc_count 1).fieldValue: ".*c++.*"→ HTTP 200, bucketc++(doc_count 1) — no over-match ofc/cc/ccc.fieldValue: ".*r&d team.*"→ HTTP 200, bucketr&d team(doc_count 1) — no empty-automaton zero-bucket result.fieldValue: "(alt\\.one|alt\\.two)"(no.*….*wrapper, aspostExactAggregateFieldOptionssends) → HTTP 200, bothalt.oneandalt.twobuckets — confirms pre-built regexps still pass through verbatim.make java_affected_run ARGS="--scope focused"→ 204/204 unit tests pass; the planner (run withmake java_affected ARGS="--scope focused") identified the impacted unit class (SearchUtilsTest) and ran it.mvn spotless:checkforopenmetadata-serviceandopenmetadata-integration-tests, andyarn lint:base+yarn pretty:baseon the changed UI files — all clean.yarn tsc:checkshows only the pre-existingOMSelectWidget.tsxerror (unchanged by this PR).Local Java test run: PASSED —
make java_affected_run ARGS="--scope focused"(SearchUtilsTest 204/204, 0 failed). Impacted integration testsSearchAggregateRbacIT,FieldNamesAggregationIT,CustomPropertyAggregationIT,TableTotalCountAggregationITran locally on both Elasticsearch and OpenSearch engines (all pass, 8+7+5+5+2+2+1+1 tests, 0 failures).Not applicable — no UI behavior change visible to Playwright.
UI screen recording:
Not applicable — backend-focused fix; the UI change (
miscAPI.ts) only removes redundant client-side escaping that the server now owns, with no user-visible behavior change. The Jest unit test pins the new contract.Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.docs/decisions/(see itsREADME.md). This description is gone fromgit logafter the squash-merge.Root cause and fix
The
bestMatchAggregationsmethod in bothElasticSearchAggregationManagerandOpenSearchAggregationManagerbuilt Lucene regexpincludepatterns for the terms aggregation that only escaped.(exact/prefix) and passed the contains pattern completely raw. Every other Lucene regexp metacharacter (()[]{}+*?|&~#@!<>=-^"\/) was left to be interpreted by the engine, so values that are legal data in OpenMetadata (Pii.Phone (mobile),R&D Team,C++) either rejected the whole_searchrequest (unbalanced/dangling regexp → HTTP 500) or silently mis-matched (&intersection,()group,|union,+/?quantifiers).The fix adds a shared
SearchUtils.escapeLuceneRegexphelper (escaping the full metacharacter set, mirroring the existingColumnAggregator.toCaseInsensitiveRegex) andSearchUtils.buildBestMatchIncludePatterns, which routes literal quick-filter values (the.*….*-wrapped shape) through escaping for all three sub-aggregations while passing pre-built regexps (e.g. the tag-FQN alternation(pii\.a|pii\.b)built by the UI'sbuildTagFqnIncludeRegexand posted viapostExactAggregateFieldOptions) through verbatim. Both aggregation managers now call the shared helper. The UI'sgetAggregateFieldOptions/postAggregateFieldOptionsstop pre-escaping withescapeESReservedCharactersso the server's single escaping pass is not double-escaped;escapeESReservedCharactersis still used for theqquery-string path.Automatic Fixes PRs can be configured here.


Confidence Score: 5/5
The PR appears safe to merge; the remaining concern is a non-blocking test gap.Findings
Summary
The PR moves escaping for quick-filter values to the server and shares it across Elasticsearch and OpenSearch.
Reviews (2) · Last reviewed commit: "fix(search): use pre-built regexp verbat..." · Reviewed by Greptile