Skip to content

Commit bc689f7

Browse files
authored
Allow setting of copy_settings in the HLRC (#39752)
#30255 introduced the `copy_settings` parameter in 6.x. This commit adds support for setting it via `setCopySettings` in the HLRC and also adjusts docs.
1 parent 053974b commit bc689f7

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ private static Request resize(ResizeRequest resizeRequest) throws IOException {
342342
params.withTimeout(resizeRequest.timeout());
343343
params.withMasterTimeout(resizeRequest.masterNodeTimeout());
344344
params.withWaitForActiveShards(resizeRequest.getTargetIndexRequest().waitForActiveShards(), ActiveShardCount.DEFAULT);
345+
params.withCopySettings(resizeRequest.getCopySettings());
345346

346347
request.setEntity(RequestConverters.createEntity(resizeRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
347348
return request;

client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,17 @@ Params withWaitForActiveShards(ActiveShardCount activeShardCount) {
909909
return withWaitForActiveShards(activeShardCount, ActiveShardCount.DEFAULT);
910910
}
911911

912+
/**
913+
* @deprecated <code>copy_settings</code> can not be set to false. If unset, behaves as <code>false</code> and won't copy settings.
914+
*/
915+
@Deprecated
916+
Params withCopySettings(Boolean setCopySettings) {
917+
if (setCopySettings != null) {
918+
return putParam("copy_settings", setCopySettings.toString());
919+
}
920+
return this;
921+
}
922+
912923
Params withIndicesOptions(IndicesOptions indicesOptions) {
913924
if (indicesOptions != null) {
914925
withIgnoreUnavailable(indicesOptions.ignoreUnavailable());

client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,12 @@ private void resizeTest(ResizeType resizeType, CheckedFunction<ResizeRequest, Re
868868
ResizeRequest resizeRequest = new ResizeRequest(indices[0], indices[1]);
869869
resizeRequest.setResizeType(resizeType);
870870
Map<String, String> expectedParams = new HashMap<>();
871+
872+
if (randomBoolean()) {
873+
resizeRequest.setCopySettings(true);
874+
expectedParams.put("copy_settings", "true");
875+
}
876+
871877
RequestConvertersTests.setRandomMasterTimeout(resizeRequest, expectedParams);
872878
RequestConvertersTests.setRandomTimeout(resizeRequest::timeout, resizeRequest.timeout(), expectedParams);
873879

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,9 +1683,13 @@ public void testShrinkIndex() throws Exception {
16831683
request.setWaitForActiveShards(2); // <1>
16841684
request.setWaitForActiveShards(ActiveShardCount.DEFAULT); // <2>
16851685
// end::shrink-index-request-waitForActiveShards
1686+
// tag::shrink-index-request-copySettings
1687+
request.setCopySettings(true); // <1>
1688+
// end::shrink-index-request-copySettings
16861689
// tag::shrink-index-request-settings
16871690
request.getTargetIndexRequest().settings(Settings.builder()
1688-
.put("index.number_of_shards", 2)); // <1>
1691+
.put("index.number_of_shards", 2) // <1>
1692+
.putNull("index.routing.allocation.require._name")); // <2>
16891693
// end::shrink-index-request-settings
16901694
// tag::shrink-index-request-aliases
16911695
request.getTargetIndexRequest().alias(new Alias("target_alias")); // <1>

docs/java-rest/high-level/indices/shrink_index.asciidoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,21 @@ returns a response, as an `int`
4747
<2> The number of active shard copies to wait for before the shrink index API
4848
returns a response, as an `ActiveShardCount`
4949

50+
["source","java",subs="attributes,callouts,macros"]
51+
--------------------------------------------------
52+
include-tagged::{doc-tests-file}[{api}-request-copySettings]
53+
--------------------------------------------------
54+
<1> Use `true` to copy the settings from the source index to the target
55+
index. This cannot be `false`. If this method is not used, default behavior is
56+
not to copy. This parameter will be removed in 8.0.0.
57+
5058
["source","java",subs="attributes,callouts,macros"]
5159
--------------------------------------------------
5260
include-tagged::{doc-tests-file}[{api}-request-settings]
5361
--------------------------------------------------
5462
<1> The settings to apply to the target index, which include the number of
5563
shards to create for it
64+
<2> Remove the allocation requirement copied from the source index
5665

5766
["source","java",subs="attributes,callouts,macros"]
5867
--------------------------------------------------

0 commit comments

Comments
 (0)