#34380·OpenMetadata

Bound the clause cost of every search path

Author: manerowCreated Oct 1, 2026Updated Oct 1, 2026
Labelsbugsearchbackend

Summary

#34369 fixes the two endpoints that broke (the NLQ keyword fallback and /v1/search/aggregate with plain-text q). This issue covers the rest of its design: making the clause cost of every search path bounded by construction, so the next mapping or settings change cannot bring too_many_nested_clauses back. Background, measurements and history are in #34369.

Why the cost is unbounded today

A query costs roughly (fields searched) × (terms each field's search-time analyzer makes from the input). After #34369, user text on the main endpoints goes through the Search Settings builder, which bounds the first factor. The second factor is still unbounded on several paths:

  • .ngram fields have no search_analyzer. In the en and ru mappings (3 to 20 character grams) the query text is cut into grams at search time too: a 21-character word becomes 189 terms on each .ngram field. The ranked partialName stage works around this per query (SearchRankingHelper.stageSearchAnalyzer), but every other path that touches these fields does not, including NLQ-generated queries and user query_filters.
  • Long input, and fuzzy expansion that grows with the index. om_analyzer splits a token at every letter/digit switch and case change, and each analyzed stage costs about one clause per resulting word part and field. On top of that, the fuzzy stage expands every part into up to 10 indexed terms per field, so its cost grows with the vocabulary of the index. The rule that turns fuzziness off past two sub-tokens counts only separators, so one long letter/digit token keeps it on. Measured on OpenSearch 3.4.0 at the default limit of 1024 with 10,000 synthetic assets, /v1/search/query fails from about 100 random letters and digits, 200 CJK characters or 60 short words like a1, and a 40-character token already costs over 500 clauses. On a nearly empty index the same 100-character input passes, which is why local runs miss it.
  • String filters and a few builders still fan out. Non-JSON query_filter/post_filter strings become a query_string without fields, and some builders can emit "fields": [] (for example when every configured field is fuzzy-only for the test case result indexes), which OpenSearch treats as "all fields".
  • Nothing measures the budget. A mapping change made for an unrelated feature changed the cost of two endpoints, and CI only noticed in a downstream nightly.

Solution design (one PR)

  1. Bound search-time ngram analysis in en and ru. Add an om_ngram_search analyzer to each mapping (same token boundaries and filters as om_ngram: split on non letters/digits, lowercase, asciifolding; plus length min 3 and truncate 20) and set search_analyzer: om_ngram_search on every om_ngram field (122 in en, 124 in ru). The query word stays one term and still matches the indexed grams. A built-in analyzer such as standard is not used because it does not fold accents and keeps underscores inside tokens. jp and zh keep their query-time grams: they use 1-2 and 2-3 character grams, which are cheap and which text without spaces needs.
  2. Keep openmetadata-ops migrate working on existing indices. A custom analyzer cannot be added to an open index, and a mapping update is all-or-nothing. Before pushing mapping properties to a live index, drop search_analyzer references to analyzers that index does not define, so every other mapping change still applies. The new analyzer takes effect at the full reindex that a 2.1 upgrade already requires.
  3. Bound string filters and empty field lists. Non-JSON query_filter/post_filter keep query_string but get an explicit field list (the asset's configured search fields). Builders never emit an empty fields; they fall back to the index's configured fields instead.
  4. Bound analyzed text by word parts. On the plain-text path, analyzed stages look at the first 24 word parts of the input, counted the way om_analyzer splits it (separators, letter/digit switches, case changes, one part per ideograph). Exact-match stages keep the full input, so long hash-like names still match exactly. The fuzzy stage also turns off past 8 word parts, so its expansion stays bounded on any index. Input longer than 24 word parts is searched as plain text even if it contains Lucene syntax characters, since it is almost always a question such as an NLQ fallback ending in ?. Shorter Lucene-syntax queries keep their structure and only have letter/digit runs longer than 128 characters truncated. On the same 10,000-asset index, every input above stays at or under 512 clauses.
  5. Guard test. For every index in indexMapping.json plus all and dataAsset, on both engines, build the query for a set of sample inputs and assert every query_string, simple_query_string and multi_match has a non-empty field list. The few manual query_string constructions on report and time-series indexes are listed explicitly with a reason.
  6. Clause-budget integration test. On OpenSearch at the default limit, send seeded random inputs (letter/digit runs of 21 to 4000 characters, a 60-word sentence, 60 short two-part words, a long CamelCase name, field syntax, wildcards, quoted phrases, accents, CJK) through /v1/search/query, /v1/search/nlq/query and /v1/search/aggregate on representative indexes, and the heaviest inputs through /v1/search/query on every index; assert HTTP 200 and no failed shards.
  7. Report the limit. The search cluster fitness report shows the effective indices.query.bool.max_clause_count on OpenSearch and Elasticsearch below 8, and warns below 1024.
  8. One limit across OM's own stacks. Remove the 4096 override from the development compose files and the Playwright/UI test harness, so local development and every OM test harness run at OpenSearch's default, the floor this design makes safe.

Behaviour changes for release notes

  • en/ru .ngram fields use a matching search analyzer after the 2.1 reindex.
  • Plain-text searches use their first 24 word parts in analyzed stages; exact-name matching still uses the full text.
  • Queries with more than 8 word parts, such as long hash-like tokens, no longer get fuzzy matching.
  • Input longer than 24 word parts is searched as plain text even if it contains Lucene syntax characters; shorter Lucene-syntax searches truncate letter/digit runs longer than 128 characters.
  • String query_filter/post_filter values search the configured fields when they contain unqualified words.
  • Development compose files and the UI test harness run at OpenSearch's default clause limit.

Out of scope

  • The ranked partialName stage forces the standard analyzer at query time, which does not fold accents, so accented partial queries can miss on that stage. Worth its own issue once every cluster has been reindexed with item 1.
  • aliases.ngram is indexed but not referenced by Search Settings.

Source: open-metadata/OpenMetadata