Fix validating params for single bucket requests (elastic/elasticsearch#622)

Original commit: elastic/x-pack-elasticsearch@42f8771bf8
This commit is contained in:
David Kyle 2017-01-03 14:59:01 +00:00 committed by GitHub
parent db3358166b
commit f8309a0706
1 changed files with 26 additions and 11 deletions

View File

@ -65,18 +65,32 @@ public class RestGetBucketsAction extends BaseRestHandler {
|| restRequest.hasParam(GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName())
|| timestamp == null) {
// Multiple buckets
// Multiple buckets, check if the param is set first so mutually exclusive
// options will only cause an error if set
if (restRequest.hasParam(GetBucketsAction.Request.START.getPreferredName())) {
request.setStart(restRequest.param(GetBucketsAction.Request.START.getPreferredName()));
}
if (restRequest.hasParam(GetBucketsAction.Request.END.getPreferredName())) {
request.setEnd(restRequest.param(GetBucketsAction.Request.END.getPreferredName()));
request.setPageParams(new PageParams(restRequest.paramAsInt(PageParams.FROM.getPreferredName(), PageParams.DEFAULT_FROM),
}
if (restRequest.hasParam(PageParams.FROM.getPreferredName()) || restRequest.hasParam(PageParams.SIZE.getPreferredName())) {
request.setPageParams(
new PageParams(restRequest.paramAsInt(PageParams.FROM.getPreferredName(), PageParams.DEFAULT_FROM),
restRequest.paramAsInt(PageParams.SIZE.getPreferredName(), PageParams.DEFAULT_SIZE)));
}
if (restRequest.hasParam(GetBucketsAction.Request.ANOMALY_SCORE.getPreferredName())) {
request.setAnomalyScore(
Double.parseDouble(restRequest.param(GetBucketsAction.Request.ANOMALY_SCORE.getPreferredName(), "0.0")));
}
if (restRequest.hasParam(GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName())) {
request.setMaxNormalizedProbability(
Double.parseDouble(restRequest.param(
GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName(), "0.0")));
}
if (restRequest.hasParam(GetBucketsAction.Request.PARTITION_VALUE.getPreferredName())) {
request.setPartitionValue(restRequest.param(GetBucketsAction.Request.PARTITION_VALUE.getPreferredName()));
}
}
// Common options
request.setExpand(restRequest.paramAsBoolean(GetBucketsAction.Request.EXPAND.getPreferredName(), false));
@ -85,4 +99,5 @@ public class RestGetBucketsAction extends BaseRestHandler {
return channel -> transportAction.execute(request, new RestStatusToXContentListener<>(channel));
}
}