-
Notifications
You must be signed in to change notification settings - Fork 24.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 Open Index API to the high level REST client #27574
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
@elasticmachine please test this |
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.
thanks a lot @olcbean I left a few comments, looks good though. I will merge this once you addressed those.
*/ | ||
public final void openIndexAsync(OpenIndexRequest openIndexRequest, ActionListener<OpenIndexResponse> listener, Header... headers) { | ||
performRequestAsyncAndParseEntity(openIndexRequest, Request::openIndex, OpenIndexResponse::fromXContent, listener, | ||
Collections.singleton(404), headers); |
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.
we need these only in IndicesClient, so that users can do client.indices().openIndex() . No need to add them here too.
OpenIndexRequest openIndexRequest = new OpenIndexRequest(indexName); | ||
OpenIndexResponse openIndexResponse = execute(openIndexRequest, highLevelClient().indices()::openIndex, | ||
highLevelClient().indices()::openIndexAsync); | ||
assertTrue(openIndexResponse.isAcknowledged()); |
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.
maybe it would be good to close the index first using the low-level REST client, then verify that opening it actually does something?
|
||
ElasticsearchException exception = expectThrows(ElasticsearchException.class, | ||
() -> execute(openIndexRequest, highLevelClient().indices()::openIndex, highLevelClient().indices()::openIndexAsync)); | ||
assertEquals(RestStatus.NOT_FOUND, exception.status()); |
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.
maybe also test the API against multiple indices?
Map<String, String> expectedParams = new HashMap<>(); | ||
setRandomTimeout(openIndexRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); | ||
setRandomMasterTimeout(openIndexRequest, expectedParams); | ||
setRandomIndicesOptions(openIndexRequest::indicesOptions, openIndexRequest::indicesOptions, expectedParams); |
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.
can we also add the set wait for active shards ?
boolean humanReadable = randomBoolean(); | ||
final XContentType xContentType = randomFrom(XContentType.values()); | ||
BytesReference originalBytes = toShuffledXContent(openIndexResponse, xContentType, ToXContent.EMPTY_PARAMS, humanReadable); | ||
|
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.
can you also add here an insertRandomFields step to verify forward compatibility (as we ignore any unknown fields rather than throwing errors)
final XContentType xContentType = randomFrom(XContentType.values()); | ||
BytesReference originalBytes = toShuffledXContent(openIndexResponse, xContentType, ToXContent.EMPTY_PARAMS, humanReadable); | ||
|
||
OpenIndexResponse parsedCreateIndexResponse; |
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.
rename this variable?
@javanna thanks for the review. Ready for a second round ;) |
test this please |
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.
thanks @olcbean I left a few more comments, nothing major. The important bit is removing the new methods from RestHighLevelClient
.
@@ -281,7 +283,7 @@ public final GetResponse get(GetRequest getRequest, Header... headers) throws IO | |||
* | |||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html">Get API on elastic.co</a> | |||
*/ | |||
public void getAsync(GetRequest getRequest, ActionListener<GetResponse> listener, Header... headers) { | |||
public final void getAsync(GetRequest getRequest, ActionListener<GetResponse> listener, Header... headers) { |
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.
thank you, seems like I left this out :)
public final void openIndexAsync(OpenIndexRequest openIndexRequest, ActionListener<OpenIndexResponse> listener, Header... headers) { | ||
performRequestAsyncAndParseEntity(openIndexRequest, Request::openIndex, OpenIndexResponse::fromXContent, listener, emptySet(), | ||
headers); | ||
} |
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.
we don't need these two methods, they are already in IndicesClient
. Can you remove them?
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.
facepalm
return randomIndices(0, 5); | ||
} | ||
|
||
private String[] randomIndices(int minIndicesNum, int maxIndicesNum) { |
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.
make this static?
assertEquals(RestStatus.NOT_FOUND, exception.status()); | ||
} | ||
|
||
private String[] randomIndices() { |
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.
maybe we can remove this method and always call the other one?
assertTrue(openIndexResponse.isAcknowledged()); | ||
|
||
for (String index : indices) { | ||
client().performRequest("GET", index + "/_search"); |
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.
check that 200 was returned?
OpenIndexRequest openIndexRequest = new OpenIndexRequest(nonExistentIndices); | ||
ElasticsearchException exception = expectThrows(ElasticsearchException.class, | ||
() -> execute(openIndexRequest, highLevelClient().indices()::openIndex, highLevelClient().indices()::openIndexAsync)); | ||
assertEquals(RestStatus.NOT_FOUND, exception.status()); |
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.
would you mind checking also that with IndicesOptions.lenientExpandOpen
we don't get back an error?
@javanna my bad! Ready for another round ;) |
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.
LGTM thanks @olcbean
test this please |
retest this please |
heya @olcbean I took the liberty to merge master in as there were conflicts and push to your remote. Running tests one last time and then merging. Thanks a lot! |
retest this please |
Thanks @javanna! |
sounds great @olcbean thank you! |
* master: (414 commits) Set ACK timeout on indices service test Implement byte array reusage in `NioTransport` (elastic#27696) [TEST] Remove leftover ES temp directories before Vagrant tests (elastic#27722) Cleanup split strings by comma method Remove unused import from AliasResolveRoutingIT Add read timeouts to http module (elastic#27713) Fix routing with leading or trailing whitespace remove await fix from FullClusterRestartIT.testRecovery Add missing 's' to tmpdir name (elastic#27721) [Issue-27716]: CONTRIBUTING.md IntelliJ configurations settings are confusing. (elastic#27717) [TEST] Now actually wait for merges Test out of order delivery of append only index and retry with an intermediate delete [TEST] remove code duplications in RequestTests [Tests] Add test for GeoShapeFieldType#setStrategyName (elastic#27703) Remove unused *Commit* classes (elastic#27714) Add test for writer operation buffer accounting (elastic#27707) [TEST] Wait for merging to complete before testing breaker Add Open Index API to the high level REST client (elastic#27574) Correcting some minor typos in comments Add unreleased v5.6.6 version ...
Add _open to the high level REST client Relates to #27205
Add
_open
to the high level REST clientRelates to #27205