diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4dff4bb058..b160101271 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Added
- Add support for knn_vector field type ([#529](https://github.com/opensearch-project/opensearch-java/pull/524))
- Add translog option object and missing translog sync interval option in index settings ([#518](https://github.com/opensearch-project/opensearch-java/pull/518))
+- Adds the option to set slices=auto for UpdateByQueryRequest, DeleteByQueryRequest and ReindexRequest ([#538](https://github.com/opensearch-project/opensearch-java/pull/538))
### Dependencies
- Bumps `com.github.jk1.dependency-license-report` from 2.2 to 2.4
diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/DeleteByQueryRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/DeleteByQueryRequest.java
index e684435b8f..516f62060c 100644
--- a/java-client/src/main/java/org/opensearch/client/opensearch/core/DeleteByQueryRequest.java
+++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/DeleteByQueryRequest.java
@@ -509,7 +509,7 @@ public final SlicedScroll slice() {
/**
* The number of slices this task should be divided into. Defaults to 1, meaning
- * the task isn't sliced into subtasks. Can be set to auto
.
+ * the task isn't sliced into subtasks. Can be set to 0 for auto
.
*
* API name: {@code slices}
*/
@@ -1125,7 +1125,7 @@ public final Builder slice(Functionauto.
+ * the task isn't sliced into subtasks. Can be set to 0 for auto
.
*
* API name: {@code slices}
*/
@@ -1327,7 +1327,7 @@ protected static void setupDeleteByQueryRequestDeserializer(ObjectDeserializer {
Map params = new HashMap<>();
if (request.slices != null) {
- params.put("slices", String.valueOf(request.slices));
+ params.put("slices", request.slices == 0 ? "auto" : String.valueOf(request.slices));
}
if (request.df != null) {
params.put("df", request.df);
diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/ReindexRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/ReindexRequest.java
index 4d15889524..fd105054e7 100644
--- a/java-client/src/main/java/org/opensearch/client/opensearch/core/ReindexRequest.java
+++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/ReindexRequest.java
@@ -219,7 +219,7 @@ public final Long size() {
/**
* The number of slices this task should be divided into. Defaults to 1, meaning
- * the task isn't sliced into subtasks. Can be set to auto
.
+ * the task isn't sliced into subtasks. Can be set to 0 for auto
.
*
* API name: {@code slices}
*/
@@ -467,7 +467,7 @@ public final Builder size(@Nullable Long value) {
/**
* The number of slices this task should be divided into. Defaults to 1, meaning
- * the task isn't sliced into subtasks. Can be set to auto
.
+ * the task isn't sliced into subtasks. Can be set to 0 for auto
.
*
* API name: {@code slices}
*/
@@ -605,7 +605,7 @@ protected static void setupReindexRequestDeserializer(ObjectDeserializer {
Map params = new HashMap<>();
if (request.slices != null) {
- params.put("slices", String.valueOf(request.slices));
+ params.put("slices", request.slices == 0 ? "auto" : String.valueOf(request.slices));
}
if (request.requestsPerSecond != null) {
params.put("requests_per_second", String.valueOf(request.requestsPerSecond));
diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/UpdateByQueryRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/UpdateByQueryRequest.java
index 847e0e8bd7..f651b23696 100644
--- a/java-client/src/main/java/org/opensearch/client/opensearch/core/UpdateByQueryRequest.java
+++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/UpdateByQueryRequest.java
@@ -525,7 +525,7 @@ public final SlicedScroll slice() {
/**
* The number of slices this task should be divided into. Defaults to 1, meaning
- * the task isn't sliced into subtasks. Can be set to auto
.
+ * the task isn't sliced into subtasks. Can be set to 0 for auto
.
*
* API name: {@code slices}
*/
@@ -1181,7 +1181,7 @@ public final Builder slice(Functionauto.
+ * the task isn't sliced into subtasks. Can be set to 0 for auto
.
*
* API name: {@code slices}
*/
@@ -1397,7 +1397,7 @@ protected static void setupUpdateByQueryRequestDeserializer(ObjectDeserializer {
Map params = new HashMap<>();
if (request.slices != null) {
- params.put("slices", String.valueOf(request.slices));
+ params.put("slices", request.slices == 0 ? "auto" : String.valueOf(request.slices));
}
if (request.df != null) {
params.put("df", request.df);
diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/DeleteByQueryRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/DeleteByQueryRequestTest.java
new file mode 100644
index 0000000000..7afa14d9a2
--- /dev/null
+++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/DeleteByQueryRequestTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.opensearch.core;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+
+public class DeleteByQueryRequestTest extends Assert {
+ @Test
+ public void testEndpointSlicesAuto() {
+ DeleteByQueryRequest deleteByQueryRequest = DeleteByQueryRequest.of(b -> b
+ .index("test-index")
+ .slices(0L));
+ Map queryParameters = DeleteByQueryRequest._ENDPOINT.queryParameters(deleteByQueryRequest);
+ assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
+ assertEquals("auto", queryParameters.get("slices"));
+ }
+
+ @Test
+ public void DeleteByQueryRequest() {
+ DeleteByQueryRequest deleteByQueryRequest = DeleteByQueryRequest.of(b -> b
+ .index("test-index")
+ .slices(6L));
+ Map queryParameters = DeleteByQueryRequest._ENDPOINT.queryParameters(deleteByQueryRequest);
+ assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
+ assertEquals("6", queryParameters.get("slices"));
+ }
+}
diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/ReindexRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/ReindexRequestTest.java
new file mode 100644
index 0000000000..22fd150b66
--- /dev/null
+++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/ReindexRequestTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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.opensearch.core;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+
+public class ReindexRequestTest extends Assert {
+ @Test
+ public void testEndpointSlicesAuto() {
+ ReindexRequest reindexRequest = ReindexRequest.of(b -> b
+ .slices(0L));
+ Map queryParameters = ReindexRequest._ENDPOINT.queryParameters(reindexRequest);
+ assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
+ assertEquals("auto", queryParameters.get("slices"));
+ }
+
+ @Test
+ public void testEndpointSlicesNumber() {
+ ReindexRequest reindexRequest = ReindexRequest.of(b -> b
+ .slices(6L));
+ Map queryParameters = ReindexRequest._ENDPOINT.queryParameters(reindexRequest);
+ assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
+ assertEquals("6", queryParameters.get("slices"));
+ }
+}
diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/UpdateByQueryRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/UpdateByQueryRequestTest.java
new file mode 100644
index 0000000000..6883dea8a3
--- /dev/null
+++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/UpdateByQueryRequestTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.opensearch.core;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+
+public class UpdateByQueryRequestTest extends Assert {
+ @Test
+ public void testEndpointSlicesAuto() {
+ UpdateByQueryRequest updateByQueryRequest = UpdateByQueryRequest.of(b -> b
+ .index("test-index")
+ .slices(0L));
+ Map queryParameters = UpdateByQueryRequest._ENDPOINT.queryParameters(updateByQueryRequest);
+ assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
+ assertEquals("auto", queryParameters.get("slices"));
+ }
+
+ @Test
+ public void testEndpointSlicesNumber() {
+ UpdateByQueryRequest updateByQueryRequest = UpdateByQueryRequest.of(b -> b
+ .index("test-index")
+ .slices(6L));
+ Map queryParameters = UpdateByQueryRequest._ENDPOINT.queryParameters(updateByQueryRequest);
+ assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
+ assertEquals("6", queryParameters.get("slices"));
+ }
+}