Repository navigation
Fix multi-node search inconsistency: preference + deterministic sort tiebreaker - #29503
Conversation
… tiebreaker On a multi-node OpenSearch/Elasticsearch cluster the same query could return reordered or different results across requests: reads bounced between shard copies (no `preference`) and the default relevance sort had no total-order tiebreaker, so equal-scored docs ordered differently per replica. - Add `preference` to OpenSearch/ElasticSearchRequestBuilder and set it per authenticated user (SearchUtils.searchPreferenceFor) so each user's queries pin to the same shard copy and stop bouncing across replicas. - Always append a name.keyword + id.keyword sort tiebreaker on every sort path (including the default and non-_score paths, where docs commonly tie), giving a deterministic total order identical across shards/replicas. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
❌ PR checklist incompleteThis 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 |
The /search/vector/query path (used by the askCollate getCompanyContext tool) ran raw approximate-kNN with no `preference`, so its results bounced across replicas on a multi-node cluster the same way the main and hybrid search did. - Add a `preference` param to VectorIndexService.search (a default 6-arg overload delegates with null) and emit it on the OpenSearchVectorService _search request via SearchUtils.appendPreferenceParam. - Derive the routing key from the request principal in VectorSearchResource through SearchUtils.searchPreferenceFor. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…dead isExport - ElasticSearchSearchManager: use Boolean.TRUE.equals(getIsHierarchy()) in the sort guard. The B2 refactor lifted the check out of the `&&` short-circuit, so an unboxed null Boolean could NPE on every non-sorted search — matches the null-safe OpenSearch side. - appendDeterministicTiebreak (both engines): guard id.keyword the same way as name.keyword, so a primary sort on id.keyword no longer adds a duplicate clause. - Drop the now-unused isExport parameter from buildSearchRequestBuilder in both managers and update call sites; the tiebreaker is applied unconditionally so export still gets it. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
🔴 Playwright Results — 1 failure(s), 18 flaky✅ 4456 passed · ❌ 1 failed · 🟡 18 flaky · ⏭️ 38 skipped
Genuine Failures (failed on all attempts)❌
|
|
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Gitar
…4789) (#29850) Backport the multi-chunk embedding fix from #29678 to 1.13, vector-pipeline only. Excludes the AI Context Platform (REST /context, MCP tools, AIContextBuilder, metric assets), which depends on 2.0-only server features (Context Center, metric->asset edge). VectorDocBuilder previously embedded only chunk 0 (~380 words) of an entity's body, so long Knowledge Articles were not semantically retrievable past their opening. VectorDocBuilder.fromEntity now emits one embedding document per body chunk into a dedicated data_asset_embeddings_chunks index (deterministic {parentId}_{chunkIndex} ids), dual-writing chunk 0 to the legacy entity-doc embedding so hybrid search is unchanged and there is no migration cliff. Stale chunks are cleaned on hard/soft delete, restore, and body shrink; a reindex backfills existing entities (missing chunk header -> re-embed, fingerprint-skip on subsequent runs). The read side (RagHitProcessor top-N chunk merge in ai-platform) already ships on 1.13 and lights up once the chunk index is populated. VectorIndexService intentionally diverges from upstream by one method: the preference/7-arg search overload (from #29503) is omitted because #29503 is not on 1.13; only the #4789 chunk methods are added. Fixes: open-metadata/openmetadata-collate#4789 Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>



Describe your changes:
Fixes #
On a multi-node OpenSearch/Elasticsearch cluster the same query could return reordered or different results across requests, because reads bounced between shard copies (no
preferencewas ever set) and the default relevance sort had no total-order tiebreaker, so equal-scored docs ordered differently per replica. This PR pins each authenticated user's searches to one shard copy via apreferencerouting key (SearchUtils.searchPreferenceFor, threaded throughOpenSearch/ElasticSearchRequestBuilderand both search managers) and always appends a deterministicname.keyword+id.keywordsort tiebreaker on every sort path (including the default and non-_scorepaths, where docs commonly tie). Together these make repeated/paginated searches return stable, identical ordering across replicas.Type of change:
High-level design:
No new API surface:
preferenceis derived from the request'sSubjectContext(per-user key) so a session pins to one shard copy without changing endpoints, and the sort change reuses the existing keyword-tiebreaker logic, extending it to the previously-uncovered default/non-_scoresort paths. Behavior is unchanged on a single-node/single-shard cluster.Tests:
Use cases covered
totalVotes) and relevance (_score) sorts produce a stable total order across replicas.Unit tests
Backend integration tests
Manual testing performed
openmetadata-serviceand verifiedspotlessis clean.number_of_replicas >= 1, run the same query repeatedly and paginate during ingestion — ordering stays stable withpreferenceset.UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes #<issue-number>above.Greptile Summary
This PR fixes search result instability on multi-node OpenSearch/Elasticsearch clusters by (1) deriving a per-user
preferencerouting key that pins each user's requests to one shard copy, and (2) always appending a deterministicname.keyword+id.keywordsort tiebreaker so equal-scored documents order identically across replicas.SearchUtils.searchPreferenceForcomputes a stable routing key from the authenticated user's name;appendPreferenceParamURL-encodes it onto raw_searchendpoints, while the request-builder path sets it on the builder directly.ElasticSearchSearchManagerandOpenSearchSearchManageris restructured: the outer guard is now!Boolean.TRUE.equals(isHierarchy)(null-safe), an explicit_score desc+ tiebreaker is added when nosortFieldParamis supplied, andappendDeterministicTiebreakguards against duplicating the primary sort field.VectorIndexServicegains a backward-compatible default overload so existing callers that don't supply a preference compile without changes.Confidence Score: 5/5
Safe to merge — all changes are internal request-building logic with no new API surface, and the null-safety regression that existed before this PR is correctly resolved with
!Boolean.TRUE.equals(...).The two mechanical changes — pinning a per-user
preferencekey and always appendingname.keyword/id.keywordtiebreakers — are narrow and well-contained. TheappendDeterministicTiebreakguard logic correctly skips the field that is already the primary sort key. TheVectorIndexServicedefault overload preserves backward compatibility cleanly. No new error paths, no schema or API changes, and behavior on a single-node cluster is unchanged.No files require special attention; the most complex logic is in the two search manager files and the
appendDeterministicTiebreakhelper, both of which read correctly.Important Files Changed
searchPreferenceFor(returns user's display name) andappendPreferenceParam(URL-encodes preference onto raw endpoints). Both methods are null-safe and straightforward.!Boolean.TRUE.equals(...);isExportdead parameter removed; preference wired in.appendDeterministicTiebreak, preference set on builder.preferencefor backward compatibility, while the new abstract method requiresString preference— clean interface evolution.preferenceparameter and routes it throughappendPreferenceParamto the raw_searchendpoint URL.subjectContext(previously discarded) and passessearchPreferenceFor(subjectContext)to the vector search call.preferencefield with fluent setter/getter and wires it into theSearchRequestbuilder with a null/empty guard.preferencefield with fluent API, applied inbuild()only when non-null/non-empty.Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant Client participant SearchResource participant SearchManager as OpenSearch/ElasticSearch SearchManager participant RequestBuilder as Request Builder participant Cluster as ES/OpenSearch Cluster Client->>SearchResource: "GET /search?q=..." SearchResource->>SearchResource: getSubjectContext(securityContext) SearchResource->>SearchManager: search(request, subjectContext) SearchManager->>SearchManager: SearchUtils.searchPreferenceFor(subjectContext) → user.getName() SearchManager->>RequestBuilder: requestBuilder.preference(userName) SearchManager->>RequestBuilder: appendDeterministicTiebreak(sortField) RequestBuilder->>Cluster: "SearchRequest{preference=userName, sort=[...tiebreaker]}" Note over Cluster: preference pins request to one shard copy per user Cluster-->>Client: Stable, deterministic results participant VectorResource participant VectorService as OpenSearchVectorService Client->>VectorResource: POST /search/vector VectorResource->>VectorResource: getSubjectContext(securityContext) VectorResource->>VectorService: search(..., searchPreferenceFor(ctx)) VectorService->>VectorService: appendPreferenceParam(endpoint, preference) VectorService->>Cluster: "POST /_search?preference=user" Cluster-->>Client: Stable results%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant Client participant SearchResource participant SearchManager as OpenSearch/ElasticSearch SearchManager participant RequestBuilder as Request Builder participant Cluster as ES/OpenSearch Cluster Client->>SearchResource: "GET /search?q=..." SearchResource->>SearchResource: getSubjectContext(securityContext) SearchResource->>SearchManager: search(request, subjectContext) SearchManager->>SearchManager: SearchUtils.searchPreferenceFor(subjectContext) → user.getName() SearchManager->>RequestBuilder: requestBuilder.preference(userName) SearchManager->>RequestBuilder: appendDeterministicTiebreak(sortField) RequestBuilder->>Cluster: "SearchRequest{preference=userName, sort=[...tiebreaker]}" Note over Cluster: preference pins request to one shard copy per user Cluster-->>Client: Stable, deterministic results participant VectorResource participant VectorService as OpenSearchVectorService Client->>VectorResource: POST /search/vector VectorResource->>VectorResource: getSubjectContext(securityContext) VectorResource->>VectorService: search(..., searchPreferenceFor(ctx)) VectorService->>VectorService: appendPreferenceParam(endpoint, preference) VectorService->>Cluster: "POST /_search?preference=user" Cluster-->>Client: Stable resultsComments Outside Diff (1)
openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java, line 1081-1086 (link)isExportparameterisExportwas previously used in the|| isExporttiebreaker condition that this PR removed. It no longer appears anywhere in the method body, making it a dead parameter. TheOpenSearchSearchManagercounterpart has the same issue (line 1127).Reviews (4): Last reviewed commit: "Merge branch 'main' into harshach/multin..." | Re-trigger Greptile