-
Notifications
You must be signed in to change notification settings - Fork 35
Add support for Amazon OpenSearch Serverless #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
harshavamsi
merged 5 commits into
opensearch-project:main
from
lawofcycles:add-support-for-opensearch-serverless
Feb 19, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aaccda3
Add support for Amazon OpenSearch Serverless
lawofcycles b5e1963
Replace Scroll API with Search After API for read pagination in serve…
lawofcycles 5473f02
Fix testNoScrollIdFromFrozenIndex to expect Scroll object instead of …
lawofcycles 497179e
Add PIT support and _id sort tiebreaker to fix data consistency and m…
lawofcycles 354f188
Merge branch 'main' into add-support-for-opensearch-serverless
harshavamsi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -209,4 +209,4 @@ public String currentNode() { | |
| public String toString() { | ||
| return settings.toString(); | ||
| } | ||
| } | ||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -348,6 +348,45 @@ Scroll scroll(String scrollId, ScrollReader reader) throws IOException { | |
| } | ||
| } | ||
|
|
||
| Scroll searchAfter(String queryUri, BytesArray baseBody, Object[] searchAfter, String pitId, String keepAlive, ScrollReader reader) throws IOException { | ||
| BytesArray body = mergeSearchAfterIntoBody(baseBody, searchAfter); | ||
| if (StringUtils.hasText(pitId)) { | ||
| body = injectPit(body, pitId, keepAlive); | ||
| } | ||
| InputStream response = client.execute(Request.Method.POST, queryUri, body).body(); | ||
| try { | ||
| return reader.read(response); | ||
| } finally { | ||
| if (response instanceof StatsAware) { | ||
| stats.aggregate(((StatsAware) response).stats()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static BytesArray injectPit(BytesArray body, String pitId, String keepAlive) { | ||
| String base = body.toString().trim(); | ||
| String pitFragment = "\"pit\":{\"id\":\"" + pitId + "\",\"keep_alive\":\"" + keepAlive + "\"}"; | ||
| return new BytesArray(base.substring(0, base.length() - 1) + "," + pitFragment + "}"); | ||
| } | ||
|
|
||
| private BytesArray mergeSearchAfterIntoBody(BytesArray baseBody, Object[] searchAfter) { | ||
| BytesArray searchAfterJson = client.buildSearchAfterBody(searchAfter); | ||
| String base = baseBody.toString().trim(); | ||
| String saFragment = searchAfterJson.toString().trim(); | ||
| String saContent = saFragment.substring(1, saFragment.length() - 1); | ||
| String merged = base.substring(0, base.length() - 1) + "," + saContent + "}"; | ||
| return new BytesArray(merged); | ||
| } | ||
|
|
||
| ScrollQuery scanLimitSearchAfter(String query, BytesArray body, long limit, ScrollReader reader, String index, String keepAlive) { | ||
| String pitId = client.createPit(index, keepAlive); | ||
| return new ScrollQuery(this, query, body, limit, reader, true, pitId, keepAlive); | ||
| } | ||
|
|
||
| public void deletePit(String pitId) { | ||
| client.deletePit(pitId); | ||
| } | ||
|
|
||
| public boolean resourceExists(boolean read) { | ||
| Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); | ||
| // cheap hit - works for exact index names, index patterns, the `_all` resource, and alias names | ||
|
|
@@ -377,18 +416,20 @@ public boolean touch() { | |
| } | ||
|
|
||
| public void delete() { | ||
| // try first a blind delete by query | ||
| try { | ||
| Resource res = resources.getResourceWrite(); | ||
| client.deleteByQuery( | ||
| res.isTyped() | ||
| ? res.index() + "/" + res.type() | ||
| : res.index(), | ||
| MatchAllQueryBuilder.MATCH_ALL); | ||
| } catch (OpenSearchHadoopInvalidRequest ehir) { | ||
| log.error("Delete by query was not successful...", ehir); | ||
|
Comment on lines
-380
to
-389
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does serverless not support delete?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nvm, saw the description |
||
| if (!this.settings.getServerlessMode()) { | ||
| // try first a blind delete by query | ||
| try { | ||
| Resource res = resources.getResourceWrite(); | ||
| client.deleteByQuery( | ||
| res.isTyped() | ||
| ? res.index() + "/" + res.type() | ||
| : res.index(), | ||
| MatchAllQueryBuilder.MATCH_ALL); | ||
| } catch (OpenSearchHadoopInvalidRequest ehir) { | ||
| log.error("Delete by query was not successful...", ehir); | ||
| } | ||
| } | ||
|
|
||
| // in ES 2.0 and higher this means scrolling and deleting the docs by hand... | ||
| // do a scroll-scan without source | ||
|
|
||
|
|
@@ -475,6 +516,8 @@ public long count(boolean read) { | |
| } | ||
|
|
||
| public boolean waitForYellow() { | ||
| // For serverless collections, waitForHealth is handled through the RestClient.waitForHealth() | ||
| // which will return appropriate result based on serverless mode | ||
| return client.waitForHealth(resources.getResourceWrite().index(), RestClient.Health.YELLOW, TimeValue.timeValueSeconds(10)); | ||
| } | ||
|
|
||
|
|
@@ -495,4 +538,4 @@ public Stats stats() { | |
| public Settings getSettings() { | ||
| return settings; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we should definitely upgrade the client to support OS versions 3 and above, but it will be a breaking change that we can address later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I'll raise PR later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking into this further, the version branching in the codebase is mostly limited to the type/typeless API distinction (
V_1_XvsV_2_X+), andV_3_Xis already defined and parseable inOpenSearchMajorVersion. Since Serverless does not expose its internal OpenSearch version throughGET /, it is unclear what version should be returned here.The current
V_2_Xworks correctly because all existing version branches treatV_2_Xand above identically (typeless path). I think we can revisit this when a concrete incompatibility surfaces, either from Serverless behavior changes.