Skip to content

fix(es): keep exact metadata lookup below max_clause_count for 300+ tables - #620

Open
Coder-xiaosuo wants to merge 1 commit into
spring-ai-alibaba:mainfrom
Coder-xiaosuo:fix-issue-608-q5-es-all-shards-failed
Open

fix(es): keep exact metadata lookup below max_clause_count for 300+ tables#620
Coder-xiaosuo wants to merge 1 commit into
spring-ai-alibaba:mainfrom
Coder-xiaosuo:fix-issue-608-q5-es-all-shards-failed

Conversation

@Coder-xiaosuo

Copy link
Copy Markdown

Which issue does this PR close?

Closes #608 (Question 5) — hasTableDocuments fails with search_phase_execution_exception: all shards failed when a datasource has 300+ tables.

What this PR does / why we need it

MetadataDocumentRetriever.findInElasticsearch serialized the metadata filter into a Lucene query_string . For an IN over 300+ table names only the first value kept the metadata.name: field prefix; the rest became bare words re-scattered across all searchable fields by index.query.default_field , pushing the query past indices.query.bool.max_clause_count (default 1024). Every shard then failed with TooManyClauses , surfaced as search_phase_execution_exception: all shards failed .

The fix stops using query_string for exact metadata retrieval and builds a native bool / term / terms DSL query instead:

  • String equality ( datasourceId , vectorType , …) matches on the auto-created metadata..keyword sub-field, so values are never analyzed or re-scattered.
  • A large IN collapses into a single terms clause — clause count stays constant (~3) regardless of how many table names are passed, so it can never exceed the limit.
    Sibling callers sharing the same getDocumentsOnlyByFilter path ( SchemaServiceImpl.getTableDocuments / getColumnDocumentsByTableName ) are fixed as well.

How to verify

  • New unit test MetadataDocumentRetrieverQueryTest (no live ES): asserts that 320 table names translate to 2 term + 1 terms ( metadata.name.keyword ) leaves and that no query_string is emitted; guards for column lookups, NIN , and EQ-only filters.

  • Local checks passed: spring-javaformat validate OK, Checkstyle 0 violations, all 5 new tests green plus related vector-store tests.
    PR Type

  • Bug fix

  • Feature

  • Refactoring

  • Documentation

…ables

findInElasticsearch serialized the metadata filter into a Lucene
query_string. For an IN over 300+ table names only the first value kept
the field prefix; the rest became bare words re-scattered across all
searchable fields by index.query.default_field, exceeding
indices.query.bool.max_clause_count (1024) and failing every shard with
TooManyClauses ("all shards failed").

Replace the query_string path with a native bool/term/terms DSL query:
string equality now matches on metadata.<key>.keyword and each multi-value
IN collapses into a single terms clause, so clause count no longer grows
with the number of table names. Also fixes the sibling getTableDocuments /
getColumnDocumentsByTableName callers sharing getDocumentsOnlyByFilter.

Closes spring-ai-alibaba#608 (issue 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] v1.0.0-rc7 怎么这么多bug啊

1 participant