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:
.ngramfields have nosearch_analyzer. In theenandrumappings (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.ngramfield. The rankedpartialNamestage works around this per query (SearchRankingHelper.stageSearchAnalyzer), but every other path that touches these fields does not, including NLQ-generated queries and userquery_filters.- Long input, and fuzzy expansion that grows with the index.
om_analyzersplits 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/queryfails from about 100 random letters and digits, 200 CJK characters or 60 short words likea1, 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_filterstrings become aquery_stringwithout 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)
- Bound search-time ngram analysis in
enandru. Add anom_ngram_searchanalyzer to each mapping (same token boundaries and filters asom_ngram: split on non letters/digits,lowercase,asciifolding; pluslengthmin 3 andtruncate20) and setsearch_analyzer: om_ngram_searchon everyom_ngramfield (122 inen, 124 inru). The query word stays one term and still matches the indexed grams. A built-in analyzer such asstandardis not used because it does not fold accents and keeps underscores inside tokens.jpandzhkeep their query-time grams: they use 1-2 and 2-3 character grams, which are cheap and which text without spaces needs. - Keep
openmetadata-ops migrateworking 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, dropsearch_analyzerreferences 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. - Bound string filters and empty field lists. Non-JSON
query_filter/post_filterkeepquery_stringbut get an explicit field list (the asset's configured search fields). Builders never emit an emptyfields; they fall back to the index's configured fields instead. - 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_analyzersplits 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. - Guard test. For every index in
indexMapping.jsonplusallanddataAsset, on both engines, build the query for a set of sample inputs and assert everyquery_string,simple_query_stringandmulti_matchhas a non-empty field list. The few manualquery_stringconstructions on report and time-series indexes are listed explicitly with a reason. - 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/queryand/v1/search/aggregateon representative indexes, and the heaviest inputs through/v1/search/queryon every index; assert HTTP 200 and no failed shards. - Report the limit. The search cluster fitness report shows the effective
indices.query.bool.max_clause_counton OpenSearch and Elasticsearch below 8, and warns below 1024. - 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.ngramfields 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_filtervalues 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
partialNamestage forces thestandardanalyzer 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.ngramis indexed but not referenced by Search Settings.
Source: open-metadata/OpenMetadata