-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add changes for Create PIT and Delete PIT rest layer and rest high level client #4064
Changes from 4 commits
49b3f01
6746775
1626cfb
3bdf1cc
6ce972e
03785b9
60b5552
dce02c2
ce306c1
94b8a6a
5203a3c
90bdb5f
1be4e8b
611a43b
f1b408c
4ec23ca
66b0ca7
2e97a58
7796ace
40ac831
fab586c
1c714c7
6412c08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,8 @@ | |
import org.opensearch.action.get.MultiGetRequest; | ||
import org.opensearch.action.index.IndexRequest; | ||
import org.opensearch.action.search.ClearScrollRequest; | ||
import org.opensearch.action.search.CreatePitRequest; | ||
import org.opensearch.action.search.DeletePitRequest; | ||
import org.opensearch.action.search.MultiSearchRequest; | ||
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.action.search.SearchScrollRequest; | ||
|
@@ -92,6 +94,7 @@ | |
import org.opensearch.index.reindex.ReindexRequest; | ||
import org.opensearch.index.reindex.UpdateByQueryRequest; | ||
import org.opensearch.index.seqno.SequenceNumbers; | ||
import org.opensearch.rest.action.search.RestCreatePitAction; | ||
import org.opensearch.rest.action.search.RestSearchAction; | ||
import org.opensearch.script.mustache.MultiSearchTemplateRequest; | ||
import org.opensearch.script.mustache.SearchTemplateRequest; | ||
|
@@ -433,9 +436,19 @@ static void addSearchRequestParams(Params params, SearchRequest searchRequest) { | |
params.putParam(RestSearchAction.TYPED_KEYS_PARAM, "true"); | ||
params.withRouting(searchRequest.routing()); | ||
params.withPreference(searchRequest.preference()); | ||
params.withIndicesOptions(searchRequest.indicesOptions()); | ||
if (searchRequest.pointInTimeBuilder() == null) { | ||
params.withIndicesOptions(searchRequest.indicesOptions()); | ||
} | ||
params.withSearchType(searchRequest.searchType().name().toLowerCase(Locale.ROOT)); | ||
params.putParam("ccs_minimize_roundtrips", Boolean.toString(searchRequest.isCcsMinimizeRoundtrips())); | ||
/** | ||
* Merging search responses as part of CCS flow to reduce roundtrips is not supported for point in time - | ||
* refer to org.opensearch.action.search.SearchResponseMerger | ||
*/ | ||
if (searchRequest.pointInTimeBuilder() != null) { | ||
params.putParam("ccs_minimize_roundtrips", "false"); | ||
bharath-techie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
params.putParam("ccs_minimize_roundtrips", Boolean.toString(searchRequest.isCcsMinimizeRoundtrips())); | ||
} | ||
if (searchRequest.getPreFilterShardSize() != null) { | ||
params.putParam("pre_filter_shard_size", Integer.toString(searchRequest.getPreFilterShardSize())); | ||
} | ||
|
@@ -464,6 +477,28 @@ static Request clearScroll(ClearScrollRequest clearScrollRequest) throws IOExcep | |
return request; | ||
} | ||
|
||
static Request createPit(CreatePitRequest createPitRequest) throws IOException { | ||
Params params = new Params(); | ||
params.putParam(RestCreatePitAction.ALLOW_PARTIAL_PIT_CREATION, Boolean.toString(createPitRequest.shouldAllowPartialPitCreation())); | ||
params.putParam(RestCreatePitAction.KEEP_ALIVE, createPitRequest.getKeepAlive()); | ||
params.withIndicesOptions(createPitRequest.indicesOptions()); | ||
Request request = new Request(HttpPost.METHOD_NAME, endpoint(createPitRequest.indices(), "_search/point_in_time")); | ||
request.addParameters(params.asMap()); | ||
request.setEntity(createEntity(createPitRequest, REQUEST_BODY_CONTENT_TYPE)); | ||
return request; | ||
} | ||
|
||
static Request deletePit(DeletePitRequest deletePitRequest) throws IOException { | ||
Request request = new Request(HttpDelete.METHOD_NAME, "/_search/point_in_time"); | ||
request.setEntity(createEntity(deletePitRequest, REQUEST_BODY_CONTENT_TYPE)); | ||
return request; | ||
} | ||
|
||
static Request deleteAllPits(DeletePitRequest deletePitRequest) { | ||
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. no use of param 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. i tried a commit which removes the param but facing issues in tests / api naming conventions check test which requires request to be part of method signature (deleteAllPitsAsync) etc. so keeping it the same for now. |
||
Request request = new Request(HttpDelete.METHOD_NAME, "/_search/point_in_time/_all"); | ||
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. no need to create variable. just use |
||
return request; | ||
} | ||
|
||
static Request multiSearch(MultiSearchRequest multiSearchRequest) throws IOException { | ||
Request request = new Request(HttpPost.METHOD_NAME, "/_msearch"); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.client; | ||
|
||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.client.methods.HttpPut; | ||
import org.junit.Before; | ||
import org.opensearch.action.search.CreatePitRequest; | ||
import org.opensearch.action.search.CreatePitResponse; | ||
import org.opensearch.action.search.DeletePitInfo; | ||
import org.opensearch.action.search.DeletePitRequest; | ||
import org.opensearch.action.search.DeletePitResponse; | ||
import org.opensearch.common.unit.TimeValue; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Tests point in time API with rest high level client | ||
*/ | ||
public class PitIT extends OpenSearchRestHighLevelClientTestCase { | ||
|
||
@Before | ||
public void indexDocuments() throws IOException { | ||
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index/_doc/1"); | ||
doc1.setJsonEntity("{\"type\":\"type1\", \"id\":1, \"num\":10, \"num2\":50}"); | ||
client().performRequest(doc1); | ||
Request doc2 = new Request(HttpPut.METHOD_NAME, "/index/_doc/2"); | ||
doc2.setJsonEntity("{\"type\":\"type1\", \"id\":2, \"num\":20, \"num2\":40}"); | ||
client().performRequest(doc2); | ||
Request doc3 = new Request(HttpPut.METHOD_NAME, "/index/_doc/3"); | ||
doc3.setJsonEntity("{\"type\":\"type1\", \"id\":3, \"num\":50, \"num2\":35}"); | ||
client().performRequest(doc3); | ||
Request doc4 = new Request(HttpPut.METHOD_NAME, "/index/_doc/4"); | ||
doc4.setJsonEntity("{\"type\":\"type2\", \"id\":4, \"num\":100, \"num2\":10}"); | ||
client().performRequest(doc4); | ||
Request doc5 = new Request(HttpPut.METHOD_NAME, "/index/_doc/5"); | ||
doc5.setJsonEntity("{\"type\":\"type2\", \"id\":5, \"num\":100, \"num2\":10}"); | ||
client().performRequest(doc5); | ||
client().performRequest(new Request(HttpPost.METHOD_NAME, "/_refresh")); | ||
} | ||
|
||
public void testCreatePit() throws IOException { | ||
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.
|
||
CreatePitRequest pitRequest = new CreatePitRequest(new TimeValue(1, TimeUnit.DAYS), true, "index"); | ||
CreatePitResponse pitResponse = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync); | ||
assertTrue(pitResponse.getId() != null); | ||
assertEquals(1, pitResponse.getTotalShards()); | ||
assertEquals(1, pitResponse.getSuccessfulShards()); | ||
assertEquals(0, pitResponse.getFailedShards()); | ||
assertEquals(0, pitResponse.getSkippedShards()); | ||
List<String> pitIds = new ArrayList<>(); | ||
pitIds.add(pitResponse.getId()); | ||
DeletePitRequest deletePitRequest = new DeletePitRequest(pitIds); | ||
DeletePitResponse deletePitResponse = execute(deletePitRequest, highLevelClient()::deletePit, highLevelClient()::deletePitAsync); | ||
assertTrue(deletePitResponse.getDeletePitResults().get(0).isSuccessful()); | ||
assertTrue(deletePitResponse.getDeletePitResults().get(0).getPitId().equals(pitResponse.getId())); | ||
} | ||
|
||
public void testDeleteAllPits() throws IOException { | ||
CreatePitRequest pitRequest = new CreatePitRequest(new TimeValue(1, TimeUnit.DAYS), true, "index"); | ||
CreatePitResponse pitResponse = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync); | ||
CreatePitResponse pitResponse1 = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync); | ||
assertTrue(pitResponse.getId() != null); | ||
assertTrue(pitResponse1.getId() != null); | ||
List<String> pitIds = new ArrayList<>(); | ||
pitIds.add("_all"); | ||
DeletePitRequest deletePitRequest = new DeletePitRequest(pitIds); | ||
DeletePitResponse deletePitResponse = execute( | ||
deletePitRequest, | ||
highLevelClient()::deleteAllPits, | ||
highLevelClient()::deleteAllPitsAsync | ||
); | ||
for (DeletePitInfo deletePitInfo : deletePitResponse.getDeletePitResults()) { | ||
assertTrue(deletePitInfo.isSuccessful()); | ||
} | ||
} | ||
} |
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.
It seems to be not needed, the next line does
params.withIndicesOptions(searchRequest.indicesOptions());
unconditionally