Skip to content

Commit

Permalink
Fixes #283 (#538)
Browse files Browse the repository at this point in the history
Signed-off-by: Uriel Dan Nudelman <urinud@gmail.com>
(cherry picked from commit 8525530)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Jul 3, 2023
1 parent ccb59f5 commit 7446254
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>auto</code>.
* the task isn't sliced into subtasks. Can be set to 0 for <code>auto</code>.
* <p>
* API name: {@code slices}
*/
Expand Down Expand Up @@ -1125,7 +1125,7 @@ public final Builder slice(Function<SlicedScroll.Builder, ObjectBuilder<SlicedSc

/**
* 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 <code>auto</code>.
* the task isn't sliced into subtasks. Can be set to 0 for <code>auto</code>.
* <p>
* API name: {@code slices}
*/
Expand Down Expand Up @@ -1327,7 +1327,7 @@ protected static void setupDeleteByQueryRequestDeserializer(ObjectDeserializer<D
request -> {
Map<String, String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>auto</code>.
* the task isn't sliced into subtasks. Can be set to 0 for <code>auto</code>.
* <p>
* API name: {@code slices}
*/
Expand Down Expand Up @@ -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 <code>auto</code>.
* the task isn't sliced into subtasks. Can be set to 0 for <code>auto</code>.
* <p>
* API name: {@code slices}
*/
Expand Down Expand Up @@ -605,7 +605,7 @@ protected static void setupReindexRequestDeserializer(ObjectDeserializer<Reindex
request -> {
Map<String, String> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>auto</code>.
* the task isn't sliced into subtasks. Can be set to 0 for <code>auto</code>.
* <p>
* API name: {@code slices}
*/
Expand Down Expand Up @@ -1181,7 +1181,7 @@ public final Builder slice(Function<SlicedScroll.Builder, ObjectBuilder<SlicedSc

/**
* 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 <code>auto</code>.
* the task isn't sliced into subtasks. Can be set to 0 for <code>auto</code>.
* <p>
* API name: {@code slices}
*/
Expand Down Expand Up @@ -1397,7 +1397,7 @@ protected static void setupUpdateByQueryRequestDeserializer(ObjectDeserializer<U
request -> {
Map<String, String> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> 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<String, String> queryParameters = DeleteByQueryRequest._ENDPOINT.queryParameters(deleteByQueryRequest);
assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
assertEquals("6", queryParameters.get("slices"));
}
}
Original file line number Diff line number Diff line change
@@ -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<String, String> 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<String, String> queryParameters = ReindexRequest._ENDPOINT.queryParameters(reindexRequest);
assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
assertEquals("6", queryParameters.get("slices"));
}
}
Original file line number Diff line number Diff line change
@@ -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<String, String> 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<String, String> queryParameters = UpdateByQueryRequest._ENDPOINT.queryParameters(updateByQueryRequest);
assertTrue("Must have a slices query parameter", queryParameters.containsKey("slices"));
assertEquals("6", queryParameters.get("slices"));
}
}

0 comments on commit 7446254

Please sign in to comment.