Null check for anomaly score filter values and default the page params

Fixes broken tests

Original commit: elastic/x-pack-elasticsearch@2ebc42515a
This commit is contained in:
David Kyle 2017-01-03 15:33:19 +00:00
parent f8309a0706
commit c58d1d43d6
2 changed files with 10 additions and 8 deletions

View File

@ -59,12 +59,16 @@ public final class BucketsQueryBuilder {
}
public BucketsQueryBuilder anomalyScoreThreshold(Double anomalyScoreFilter) {
bucketsQuery.anomalyScoreFilter = anomalyScoreFilter;
if (anomalyScoreFilter != null) {
bucketsQuery.anomalyScoreFilter = anomalyScoreFilter;
}
return this;
}
public BucketsQueryBuilder normalizedProbabilityThreshold(Double normalizedProbability) {
bucketsQuery.normalizedProbability = normalizedProbability;
if (normalizedProbability != null) {
bucketsQuery.normalizedProbability = normalizedProbability;
}
return this;
}

View File

@ -65,6 +65,10 @@ public class RestGetBucketsAction extends BaseRestHandler {
|| restRequest.hasParam(GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName())
|| timestamp == null) {
request.setPageParams(
new PageParams(restRequest.paramAsInt(PageParams.FROM.getPreferredName(), PageParams.DEFAULT_FROM),
restRequest.paramAsInt(PageParams.SIZE.getPreferredName(), PageParams.DEFAULT_SIZE)));
// 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())) {
@ -73,11 +77,6 @@ public class RestGetBucketsAction extends BaseRestHandler {
if (restRequest.hasParam(GetBucketsAction.Request.END.getPreferredName())) {
request.setEnd(restRequest.param(GetBucketsAction.Request.END.getPreferredName()));
}
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")));
@ -99,5 +98,4 @@ public class RestGetBucketsAction extends BaseRestHandler {
return channel -> transportAction.execute(request, new RestStatusToXContentListener<>(channel));
}
}