diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/BucketsQueryBuilder.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/BucketsQueryBuilder.java index 9cc94be8577..2843b0c15a0 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/BucketsQueryBuilder.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/persistence/BucketsQueryBuilder.java @@ -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; } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/rest/results/RestGetBucketsAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/rest/results/RestGetBucketsAction.java index 326a1bed8f3..240356f1973 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/rest/results/RestGetBucketsAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/rest/results/RestGetBucketsAction.java @@ -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)); } - }