Skip to content

Commit 8525530

Browse files
authored
Fixes #283 (#538)
Signed-off-by: Uriel Dan Nudelman <urinud@gmail.com>
1 parent 1323796 commit 8525530

7 files changed

Lines changed: 116 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3030
### Added
3131
- Add support for knn_vector field type ([#529](https://github.com/opensearch-project/opensearch-java/pull/524))
3232
- Add translog option object and missing translog sync interval option in index settings ([#518](https://github.com/opensearch-project/opensearch-java/pull/518))
33+
- Adds the option to set slices=auto for UpdateByQueryRequest, DeleteByQueryRequest and ReindexRequest ([#538](https://github.com/opensearch-project/opensearch-java/pull/538))
3334

3435
### Dependencies
3536
- Bumps `jackson` from 2.14.2 to 2.15.2 ((#537)[https://github.com/opensearch-project/opensearch-java/pull/537])

java-client/src/main/java/org/opensearch/client/opensearch/core/DeleteByQueryRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ public final SlicedScroll slice() {
509509

510510
/**
511511
* The number of slices this task should be divided into. Defaults to 1, meaning
512-
* the task isn't sliced into subtasks. Can be set to <code>auto</code>.
512+
* the task isn't sliced into subtasks. Can be set to 0 for <code>auto</code>.
513513
* <p>
514514
* API name: {@code slices}
515515
*/
@@ -1125,7 +1125,7 @@ public final Builder slice(Function<SlicedScroll.Builder, ObjectBuilder<SlicedSc
11251125

11261126
/**
11271127
* The number of slices this task should be divided into. Defaults to 1, meaning
1128-
* the task isn't sliced into subtasks. Can be set to <code>auto</code>.
1128+
* the task isn't sliced into subtasks. Can be set to 0 for <code>auto</code>.
11291129
* <p>
11301130
* API name: {@code slices}
11311131
*/
@@ -1327,7 +1327,7 @@ protected static void setupDeleteByQueryRequestDeserializer(ObjectDeserializer<D
13271327
request -> {
13281328
Map<String, String> params = new HashMap<>();
13291329
if (request.slices != null) {
1330-
params.put("slices", String.valueOf(request.slices));
1330+
params.put("slices", request.slices == 0 ? "auto" : String.valueOf(request.slices));
13311331
}
13321332
if (request.df != null) {
13331333
params.put("df", request.df);

java-client/src/main/java/org/opensearch/client/opensearch/core/ReindexRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public final Long size() {
219219

220220
/**
221221
* The number of slices this task should be divided into. Defaults to 1, meaning
222-
* the task isn't sliced into subtasks. Can be set to <code>auto</code>.
222+
* the task isn't sliced into subtasks. Can be set to 0 for <code>auto</code>.
223223
* <p>
224224
* API name: {@code slices}
225225
*/
@@ -467,7 +467,7 @@ public final Builder size(@Nullable Long value) {
467467

468468
/**
469469
* The number of slices this task should be divided into. Defaults to 1, meaning
470-
* the task isn't sliced into subtasks. Can be set to <code>auto</code>.
470+
* the task isn't sliced into subtasks. Can be set to 0 for <code>auto</code>.
471471
* <p>
472472
* API name: {@code slices}
473473
*/
@@ -605,7 +605,7 @@ protected static void setupReindexRequestDeserializer(ObjectDeserializer<Reindex
605605
request -> {
606606
Map<String, String> params = new HashMap<>();
607607
if (request.slices != null) {
608-
params.put("slices", String.valueOf(request.slices));
608+
params.put("slices", request.slices == 0 ? "auto" : String.valueOf(request.slices));
609609
}
610610
if (request.requestsPerSecond != null) {
611611
params.put("requests_per_second", String.valueOf(request.requestsPerSecond));

java-client/src/main/java/org/opensearch/client/opensearch/core/UpdateByQueryRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ public final SlicedScroll slice() {
525525

526526
/**
527527
* The number of slices this task should be divided into. Defaults to 1, meaning
528-
* the task isn't sliced into subtasks. Can be set to <code>auto</code>.
528+
* the task isn't sliced into subtasks. Can be set to 0 for <code>auto</code>.
529529
* <p>
530530
* API name: {@code slices}
531531
*/
@@ -1181,7 +1181,7 @@ public final Builder slice(Function<SlicedScroll.Builder, ObjectBuilder<SlicedSc
11811181

11821182
/**
11831183
* The number of slices this task should be divided into. Defaults to 1, meaning
1184-
* the task isn't sliced into subtasks. Can be set to <code>auto</code>.
1184+
* the task isn't sliced into subtasks. Can be set to 0 for <code>auto</code>.
11851185
* <p>
11861186
* API name: {@code slices}
11871187
*/
@@ -1397,7 +1397,7 @@ protected static void setupUpdateByQueryRequestDeserializer(ObjectDeserializer<U
13971397
request -> {
13981398
Map<String, String> params = new HashMap<>();
13991399
if (request.slices != null) {
1400-
params.put("slices", String.valueOf(request.slices));
1400+
params.put("slices", request.slices == 0 ? "auto" : String.valueOf(request.slices));
14011401
}
14021402
if (request.df != null) {
14031403
params.put("df", request.df);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.client.opensearch.core;
10+
11+
import org.junit.Assert;
12+
import org.junit.Test;
13+
14+
import java.util.Map;
15+
16+
public class DeleteByQueryRequestTest extends Assert {
17+
@Test
18+
public void testEndpointSlicesAuto() {
19+
DeleteByQueryRequest deleteByQueryRequest = DeleteByQueryRequest.of(b -> b
20+
.index("test-index")
21+
.slices(0L));
22+
Map<String, String> queryParameters = DeleteByQueryRequest._ENDPOINT.queryParameters(deleteByQueryRequest);
23+
assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
24+
assertEquals("auto", queryParameters.get("slices"));
25+
}
26+
27+
@Test
28+
public void DeleteByQueryRequest() {
29+
DeleteByQueryRequest deleteByQueryRequest = DeleteByQueryRequest.of(b -> b
30+
.index("test-index")
31+
.slices(6L));
32+
Map<String, String> queryParameters = DeleteByQueryRequest._ENDPOINT.queryParameters(deleteByQueryRequest);
33+
assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
34+
assertEquals("6", queryParameters.get("slices"));
35+
}
36+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.client.opensearch.core;
10+
11+
import org.junit.Assert;
12+
import org.junit.Test;
13+
14+
import java.util.Map;
15+
16+
public class ReindexRequestTest extends Assert {
17+
@Test
18+
public void testEndpointSlicesAuto() {
19+
ReindexRequest reindexRequest = ReindexRequest.of(b -> b
20+
.slices(0L));
21+
Map<String, String> queryParameters = ReindexRequest._ENDPOINT.queryParameters(reindexRequest);
22+
assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
23+
assertEquals("auto", queryParameters.get("slices"));
24+
}
25+
26+
@Test
27+
public void testEndpointSlicesNumber() {
28+
ReindexRequest reindexRequest = ReindexRequest.of(b -> b
29+
.slices(6L));
30+
Map<String, String> queryParameters = ReindexRequest._ENDPOINT.queryParameters(reindexRequest);
31+
assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
32+
assertEquals("6", queryParameters.get("slices"));
33+
}
34+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.client.opensearch.core;
10+
11+
import org.junit.Assert;
12+
import org.junit.Test;
13+
14+
import java.util.Map;
15+
16+
public class UpdateByQueryRequestTest extends Assert {
17+
@Test
18+
public void testEndpointSlicesAuto() {
19+
UpdateByQueryRequest updateByQueryRequest = UpdateByQueryRequest.of(b -> b
20+
.index("test-index")
21+
.slices(0L));
22+
Map<String, String> queryParameters = UpdateByQueryRequest._ENDPOINT.queryParameters(updateByQueryRequest);
23+
assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
24+
assertEquals("auto", queryParameters.get("slices"));
25+
}
26+
27+
@Test
28+
public void testEndpointSlicesNumber() {
29+
UpdateByQueryRequest updateByQueryRequest = UpdateByQueryRequest.of(b -> b
30+
.index("test-index")
31+
.slices(6L));
32+
Map<String, String> queryParameters = UpdateByQueryRequest._ENDPOINT.queryParameters(updateByQueryRequest);
33+
assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
34+
assertEquals("6", queryParameters.get("slices"));
35+
}
36+
}

0 commit comments

Comments
 (0)