Skip to content

Fixes #37345: keep glossary synonym n-gram queries under the clause limit - #37385

Merged
mohityadav766 merged 1 commit into
mainfrom
fix/glossary-synonym-ngram-clauses
Nov 9, 2026
Merged

mohityadav766 merged 1 commit into
mainfrom
fix/glossary-synonym-ngram-clauses

Conversation

@mohityadav766

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #37345

Since #34052 added synonyms.ngram to the glossary term mapping on 11-05, SearchCountConsistencyIT.compositeAliasCountsIncludeGovernanceWithTheSameMatchingRules has failed on every run of main's nightly embedded search lane: openmetadata-nightly runs 42332334156, 42441273737 and 42571915700. It also fails locally on every run. The glossary term shard rejects the composite-alias search:

Search completed with 1 of 25 shards failing. Shard failures:
openmetadata_glossary_term_search_index_rebuild_…[0]: query_shard_exception - failed to create query: maxClauseCount is set to 1024

Cause.

Fix. In the en and ru mappings, synonyms.ngram keeps indexing n-grams but analyzes the query with om_compound_analyzer. That analyzer lowercases, ASCII-folds, splits on case changes, digits and underscores, and doesn't stem.

  • Partial matching still works. A word inside a synonym matches, because the stored n-grams include it. That's what Glossary synonym matching is degraded by a broken synonyms mapping #33456 asked for.
  • Bounded clauses. A query costs one clause per word on this field instead of one per n-gram.
  • zh is unchanged. Its om_ngram makes 2–3-character grams, so its query clauses stay few, and Chinese partial matching depends on n-gramming the query.
  • No reindex needed. search_analyzer can be updated on an existing field, so the mapping update applies it in place.

name.ngram and displayName.ngram still n-gram the query, so a single word of roughly 40 or more characters can still reach the limit through them. That predates #34052 and is left alone here.

Type of change:

  • Bug fix

High-level design:

N/A — two-line mapping change.

Tests:

Use cases covered

  • The composite-alias count search with the namespaced query returns counts again instead of failing the glossary term shard.
  • A word inside a glossary term synonym matches synonyms.ngram.
  • An 80-letter query on synonyms.ngram stays under the 1024-clause limit. It was 1,251 n-gram clauses before.

Unit tests

  • Not applicable (mapping-only change).

Backend integration tests

  • SearchCountConsistencyIT: 6/6 with this change. On main without it, it fails with the error above.
  • New GlossarySynonymNgramIT queries synonyms.ngram on the glossary term index through the test-support search endpoint. It passes with this change; on main's mapping it fails on the 80-letter query with HTTP 400 … query_shard_exception: failed to create query: maxClauseCount is set to 1024, while the synonym-word check passes either way.

Both ran embedded (PostgreSQL + OpenSearch):
mvn -pl openmetadata-integration-tests -am verify -P search-it -Dit.test=SearchCountConsistencyIT,GlossarySynonymNgramIT -DdatabaseType=postgres -DsearchType=opensearch -Djpw.data.mode=ingest

Ingestion integration tests

  • Not applicable.

Playwright (UI) tests

  • Not applicable (no UI changes).

UI screen recording:

Not applicable — no UI change.

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.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

🤖 Generated with Claude Code

…imit

synonyms.ngram, added by #34052, used om_ngram to analyze the query as well as the index, so every query word became one clause per 3-20-character n-gram. Together with name.ngram and displayName.ngram, that took the composite-alias search past the glossary term shard's 1024-clause limit. SearchCountConsistencyIT has failed in main's nightly embedded search lane on every run since 11-05.

The en and ru mappings now analyze synonyms.ngram queries with om_compound_analyzer. A word inside a synonym still matches the stored n-grams, at one clause per word. zh keeps its 2-3-character n-grams on both sides; they stay few, and Chinese partial matching needs them.

GlossarySynonymNgramIT covers both behaviors. On the previous mapping, its 80-letter query fails with maxClauseCount.
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Nov 9, 2026
Comment on lines 320 to 324
"ngram": {
"type": "text",
"analyzer": "om_ngram"
"analyzer": "om_ngram",
"search_analyzer": "om_compound_analyzer"
}

@gitar-bot gitar-bot Bot Nov 9, 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: Query-side analyzer rule for synonyms.ngram is not recorded anywhere

This PR sets a rule that keeps queries under the clause limit, but the rule exists only in the PR description. No record in docs/decisions/ mentions n-gram fields, search_analyzer or the clause limit. The repo squash-merges, so the reasoning behind the en/ru vs. zh/jp/ko split won't reach git log. A later change could set the zh/jp/ko mappings the same way as en/ru and break Chinese partial matching. Or it could switch synonyms.ngram back to n-gramming the query and bring back the 1024-clause failure caught by SearchCountConsistencyIT. This is also the latest of several PRs on the same n-gram trade-off (#34052, #33456, #22108).

The record would say: "On the glossary term index, synonyms.ngram indexes 3–20-character n-grams (om_ngram) but analyzes queries as whole words (search_analyzer: om_compound_analyzer), so each query word costs one clause instead of one per n-gram. The zh/jp/ko mappings keep n-gramming the query, because their 1–3-character grams keep the clause count low and CJK partial matching depends on it. name.ngram and displayName.ngram still n-gram the query, and a single word of about 40+ characters can still hit the clause limit through them." This comes from the description's points that the change keeps "each query word to one clause", that "the zh mapping is unchanged, since its short n-grams keep query clauses few and Chinese partial matching depends on n-gramming the query", and the out-of-scope note about name/displayName.ngram.

Add a decision record, e.g. docs/decisions/2026-11-07-glossary-synonym-ngrams-are-matched-by-whole-query-words.md, that states the rule above, and have the mapping/test cite it as ADR:2026-11-07-glossary-synonym-ngrams-are-matched-by-whole-query-words.:

# Glossary synonym n-grams are matched by whole query words

Status: Accepted

On the glossary term index, `synonyms.ngram` is indexed with `om_ngram` (3–20 chars)
and searched with `om_compound_analyzer`, so a query costs one clause per word and
stays under the 1024-clause limit. zh/jp/ko keep n-gramming the query: their 1–3 char
grams keep clause counts low and CJK partial matching needs it. `name.ngram` and
`displayName.ngram` still n-gram the query; words of ~40+ chars can exceed the limit.

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Nov 9, 2026 •

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

🟡 Medium risk · Changing English and Russian synonym query analysis could alter matching and omit glossary terms when queries tokenize differently.

Keeps glossary synonym n-gram queries under the 1024-clause limit by setting search_analyzer to om_compound_analyzer on synonyms.ngram in the en and ru glossary term mappings, leaving zh unchanged. Changes requested: the query-side analyzer rule for synonyms.ngram is recorded only in the PR description, not in docs/decisions/, so a later change could revert it and reintroduce the clause-limit failure or break Chinese partial matching.

⚠️ Quality: Query-side analyzer rule for synonyms.ngram is not recorded anywhere

📄 openmetadata-spec/src/main/resources/elasticsearch/en/glossary_term_index_mapping.json:320-324 📄 openmetadata-spec/src/main/resources/elasticsearch/ru/glossary_term_index_mapping.json:332-336

This PR sets a rule that keeps queries under the clause limit, but the rule exists only in the PR description. No record in docs/decisions/ mentions n-gram fields, search_analyzer or the clause limit. The repo squash-merges, so the reasoning behind the en/ru vs. zh/jp/ko split won't reach git log. A later change could set the zh/jp/ko mappings the same way as en/ru and break Chinese partial matching. Or it could switch synonyms.ngram back to n-gramming the query and bring back the 1024-clause failure caught by SearchCountConsistencyIT. This is also the latest of several PRs on the same n-gram trade-off (#34052, #33456, #22108).

The record would say: "On the glossary term index, synonyms.ngram indexes 3–20-character n-grams (om_ngram) but analyzes queries as whole words (search_analyzer: om_compound_analyzer), so each query word costs one clause instead of one per n-gram. The zh/jp/ko mappings keep n-gramming the query, because their 1–3-character grams keep the clause count low and CJK partial matching depends on it. name.ngram and displayName.ngram still n-gram the query, and a single word of about 40+ characters can still hit the clause limit through them." This comes from the description's points that the change keeps "each query word to one clause", that "the zh mapping is unchanged, since its short n-grams keep query clauses few and Chinese partial matching depends on n-gramming the query", and the out-of-scope note about name/displayName.ngram.

Add a decision record, e.g. docs/decisions/2026-11-07-glossary-synonym-ngrams-are-matched-by-whole-query-words.md, that states the rule above, and have the mapping/test cite it as ADR:2026-11-07-glossary-synonym-ngrams-are-matched-by-whole-query-words.
# Glossary synonym n-grams are matched by whole query words

Status: Accepted

On the glossary term index, `synonyms.ngram` is indexed with `om_ngram` (3–20 chars)
and searched with `om_compound_analyzer`, so a query costs one clause per word and
stays under the 1024-clause limit. zh/jp/ko keep n-gramming the query: their 1–3 char
grams keep clause counts low and CJK partial matching needs it. `name.ngram` and
`displayName.ngram` still n-gram the query; words of ~40+ chars can exceed the limit.
🤖 Prompt for agents
Code Review: Keeps glossary synonym n-gram queries under the 1024-clause limit by setting `search_analyzer` to `om_compound_analyzer` on `synonyms.ngram` in the en and ru glossary term mappings, leaving zh unchanged. Changes requested: the query-side analyzer rule for `synonyms.ngram` is recorded only in the PR description, not in `docs/decisions/`, so a later change could revert it and reintroduce the clause-limit failure or break Chinese partial matching.

1. ⚠️ Quality: Query-side analyzer rule for synonyms.ngram is not recorded anywhere
   Files: openmetadata-spec/src/main/resources/elasticsearch/en/glossary_term_index_mapping.json:320-324, openmetadata-spec/src/main/resources/elasticsearch/ru/glossary_term_index_mapping.json:332-336

   This PR sets a rule that keeps queries under the clause limit, but the rule exists only in the PR description. No record in `docs/decisions/` mentions n-gram fields, `search_analyzer` or the clause limit. The repo squash-merges, so the reasoning behind the en/ru vs. zh/jp/ko split won't reach `git log`. A later change could set the zh/jp/ko mappings the same way as en/ru and break Chinese partial matching. Or it could switch `synonyms.ngram` back to n-gramming the query and bring back the 1024-clause failure caught by `SearchCountConsistencyIT`. This is also the latest of several PRs on the same n-gram trade-off (#34052, #33456, #22108).
   
   The record would say: "On the glossary term index, `synonyms.ngram` indexes 3–20-character n-grams (`om_ngram`) but analyzes queries as whole words (`search_analyzer: om_compound_analyzer`), so each query word costs one clause instead of one per n-gram. The zh/jp/ko mappings keep n-gramming the query, because their 1–3-character grams keep the clause count low and CJK partial matching depends on it. `name.ngram` and `displayName.ngram` still n-gram the query, and a single word of about 40+ characters can still hit the clause limit through them." This comes from the description's points that the change keeps "each query word to one clause", that "the zh mapping is unchanged, since its short n-grams keep query clauses few and Chinese partial matching depends on n-gramming the query", and the out-of-scope note about name/displayName.ngram.

   Fix (Add a decision record, e.g. docs/decisions/2026-11-07-glossary-synonym-ngrams-are-matched-by-whole-query-words.md, that states the rule above, and have the mapping/test cite it as ADR:2026-11-07-glossary-synonym-ngrams-are-matched-by-whole-query-words.):
   # Glossary synonym n-grams are matched by whole query words
   
   Status: Accepted
   
   On the glossary term index, `synonyms.ngram` is indexed with `om_ngram` (3–20 chars)
   and searched with `om_compound_analyzer`, so a query costs one clause per word and
   stays under the 1024-clause limit. zh/jp/ko keep n-gramming the query: their 1–3 char
   grams keep clause counts low and CJK partial matching needs it. `name.ngram` and
   `displayName.ngram` still n-gram the query; words of ~40+ chars can exceed the limit.

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

@mohityadav766
mohityadav766 merged commit 44bd366 into main Nov 9, 2026
63 of 64 checks passed
@mohityadav766
mohityadav766 deleted the fix/glossary-synonym-ngram-clauses branch November 9, 2026 07:26
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.

Java IT nightly: make it green, then split it into a heavy nightly tier and a fast on-demand tier

2 participants