feat(search): add OpenSearch support via backward-compatible client abstraction#408
Open
SaitejaKommi wants to merge 5 commits intoopenfoodfacts:mainfrom
Open
feat(search): add OpenSearch support via backward-compatible client abstraction#408SaitejaKommi wants to merge 5 commits intoopenfoodfacts:mainfrom
SaitejaKommi wants to merge 5 commits intoopenfoodfacts:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces native OpenSearch support to the project while fully preserving the existing Elasticsearch integration.
A new
SearchClientabstraction layer enables the application to run against either backend engine without changing higher-level search logic. Query generation continues to leverage existing tooling, while execution is routed through a backend-compatible client layer.Elasticsearch remains the default and fully backward-compatible engine, while OpenSearch is now available as an opt-in alternative.
What Changed
Added Search Client Abstraction
Created:
search_client.pyIntroduced a centralized
SearchClientwrapper that dynamically routes operations based on:Supported operations include:
.search().index().bulk().indices.*Decoupled Query Execution
Updated modules such as:
query.pyapi.pyReplaced hardcoded direct
.execute()flows with dictionary payload execution throughSearchClient.This cleanly separates:
Normalized Backend API Differences
Implemented compatibility mappings inside
SearchClientto handle differences between:elasticsearch-py(v8 style kwargs usage)opensearch-py(flat body payload expectations)Unified Exception Handling
Exposed backend-agnostic exceptions such as:
ApiErrorNotFoundErrorThis allows application code to safely catch equivalent failures regardless of selected engine.
Docker Development Support
Added:
docker-compose.override.ymlThis enables local engine swapping to:
opensearchproject/opensearch:latestfor development and testing.
Compatibility
Elasticsearch
OpenSearch
Enabled via:
Provides native alternative backend support without application-level changes.
Validation
Full verification completed successfully against both engines:
Performance
Synthetic benchmarking showed comparable:
No regressions were observed.
Affected Files
search_client.pyquery.pyapi.pydocker-compose.override.ymlNotes
Any backend-specific indexing schema or bulk API differences are handled internally within
SearchClient.This PR focuses on extensibility and multi-engine support while keeping unrelated modules largely unchanged.