Fix AbstractBulkByScrollRequest slices parameter via Rest (#53068)
Currently the AbstractBulkByScrollRequest accepts slice values of 0 via its `setSlices` method, denoting the "auto" slicing behaviour that is usable by settting the "slices=auto" parameter on rest requests. When using the High Level Rest Client, however, we send the 0 value as an integer, which is then rejected as invalid by `AbstractBulkByScrollRequest#parseSlices`. Instead of making parsing of the rest request more lenient, this PR opts for changing the RequestConverter logic in the client to translate 0 values to "auto" on the rest requests. Closes #53044
This commit is contained in:
parent
d145b5536f
commit
9e561c2921
|
@ -925,6 +925,10 @@ final class RequestConverters {
|
|||
}
|
||||
|
||||
Params withSlices(int slices) {
|
||||
if (slices == 0) {
|
||||
// translate to "auto" value in rest request so the receiving end doesn't throw error
|
||||
return putParam("slices", AbstractBulkByScrollRequest.AUTO_SLICES_VALUE);
|
||||
}
|
||||
return putParam("slices", String.valueOf(slices));
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,7 @@ import org.elasticsearch.index.rankeval.RankEvalRequest;
|
|||
import org.elasticsearch.index.rankeval.RankEvalSpec;
|
||||
import org.elasticsearch.index.rankeval.RatedRequest;
|
||||
import org.elasticsearch.index.rankeval.RestRankEvalAction;
|
||||
import org.elasticsearch.index.reindex.AbstractBulkByScrollRequest;
|
||||
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
||||
import org.elasticsearch.index.reindex.ReindexRequest;
|
||||
import org.elasticsearch.index.reindex.RemoteInfo;
|
||||
|
@ -497,9 +498,13 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
reindexRequest.setSourceQuery(new TermQueryBuilder("foo", "fooval"));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
int slices = randomInt(100);
|
||||
int slices = randomIntBetween(0,4);
|
||||
reindexRequest.setSlices(slices);
|
||||
expectedParams.put("slices", String.valueOf(slices));
|
||||
if (slices == 0) {
|
||||
expectedParams.put("slices", AbstractBulkByScrollRequest.AUTO_SLICES_VALUE);
|
||||
} else {
|
||||
expectedParams.put("slices", Integer.toString(slices));
|
||||
}
|
||||
} else {
|
||||
expectedParams.put("slices", "1");
|
||||
}
|
||||
|
@ -567,7 +572,11 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
}
|
||||
if (randomBoolean()) {
|
||||
int slices = randomIntBetween(0, 4);
|
||||
if (slices == 0) {
|
||||
expectedParams.put("slices", AbstractBulkByScrollRequest.AUTO_SLICES_VALUE);
|
||||
} else {
|
||||
expectedParams.put("slices", Integer.toString(slices));
|
||||
}
|
||||
updateByQueryRequest.setSlices(slices);
|
||||
} else {
|
||||
expectedParams.put("slices", "1");
|
||||
|
@ -632,7 +641,11 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
}
|
||||
if (randomBoolean()) {
|
||||
int slices = randomIntBetween(0, 4);
|
||||
if (slices == 0) {
|
||||
expectedParams.put("slices", AbstractBulkByScrollRequest.AUTO_SLICES_VALUE);
|
||||
} else {
|
||||
expectedParams.put("slices", Integer.toString(slices));
|
||||
}
|
||||
deleteByQueryRequest.setSlices(slices);
|
||||
} else {
|
||||
expectedParams.put("slices", "1");
|
||||
|
|
|
@ -402,6 +402,7 @@ public abstract class AbstractBulkByScrollRequest<Self extends AbstractBulkByScr
|
|||
|
||||
/**
|
||||
* The number of slices this task should be divided into. Defaults to 1 meaning the task isn't sliced into subtasks.
|
||||
* A value of 0 is equivalent to the "auto" slices parameter of the Rest API.
|
||||
*/
|
||||
public Self setSlices(int slices) {
|
||||
if (slices < 0) {
|
||||
|
|
Loading…
Reference in New Issue