diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/GetBucketsAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/GetBucketsAction.java index 399f324ca4c..5b43f60907b 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/GetBucketsAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/GetBucketsAction.java @@ -64,7 +64,7 @@ public class GetBucketsAction extends Action request.jobId = jobId, Job.ID); PARSER.declareString(Request::setTimestamp, Result.TIMESTAMP); PARSER.declareBoolean(Request::setExpand, EXPAND); - PARSER.declareBoolean(Request::setIncludeInterim, INCLUDE_INTERIM); + PARSER.declareBoolean(Request::setExcludeInterim, EXCLUDE_INTERIM); PARSER.declareStringOrNull(Request::setStart, START); PARSER.declareStringOrNull(Request::setEnd, END); PARSER.declareObject(Request::setPageParams, PageParams.PARSER, PageParams.PAGE); @@ -94,7 +94,7 @@ public class GetBucketsAction extends Action request.jobId = jobId, Job.ID); PARSER.declareStringOrNull(Request::setStart, START); PARSER.declareStringOrNull(Request::setEnd, END); - PARSER.declareBoolean(Request::setIncludeInterim, INCLUDE_INTERIM); + PARSER.declareBoolean(Request::setExcludeInterim, EXCLUDE_INTERIM); PARSER.declareObject(Request::setPageParams, PageParams.PARSER, PageParams.PAGE); PARSER.declareDouble(Request::setAnomalyScore, ANOMALY_SCORE); PARSER.declareString(Request::setSort, SORT_FIELD); @@ -94,7 +94,7 @@ extends Action listener) { jobManager.getJobOrThrowIfUnknown(request.jobId); - InfluencersQueryBuilder.InfluencersQuery query = new InfluencersQueryBuilder().includeInterim(request.includeInterim) + InfluencersQueryBuilder.InfluencersQuery query = new InfluencersQueryBuilder().includeInterim(request.excludeInterim == false) .start(request.start).end(request.end).from(request.pageParams.getFrom()).size(request.pageParams.getSize()) .anomalyScoreThreshold(request.anomalyScoreFilter).sortField(request.sort).sortDescending(request.descending).build(); jobProvider.influencers(request.jobId, query, page -> listener.onResponse(new Response(page)), listener::onFailure, client); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/GetRecordsAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/GetRecordsAction.java index 41db282c076..3c39fbf2249 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/GetRecordsAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/GetRecordsAction.java @@ -65,7 +65,7 @@ public class GetRecordsAction extends Action client.execute(GetBucketsAction.INSTANCE, request, new RestToXContentListener<>(channel)); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetInfluencersAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetInfluencersAction.java index 61359cab8da..79c79d8a535 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetInfluencersAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetInfluencersAction.java @@ -44,7 +44,7 @@ public class RestGetInfluencersAction extends BaseRestHandler { request = new GetInfluencersAction.Request(jobId); request.setStart(start); request.setEnd(end); - request.setIncludeInterim(restRequest.paramAsBoolean(GetInfluencersAction.Request.INCLUDE_INTERIM.getPreferredName(), false)); + request.setExcludeInterim(restRequest.paramAsBoolean(GetInfluencersAction.Request.EXCLUDE_INTERIM.getPreferredName(), false)); request.setPageParams(new PageParams(restRequest.paramAsInt(PageParams.FROM.getPreferredName(), PageParams.DEFAULT_FROM), restRequest.paramAsInt(PageParams.SIZE.getPreferredName(), PageParams.DEFAULT_SIZE))); request.setAnomalyScore( diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java index de0394d7185..c54b89fa266 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java @@ -42,7 +42,7 @@ public class RestGetRecordsAction extends BaseRestHandler { request = new GetRecordsAction.Request(jobId); request.setStart(restRequest.param(GetRecordsAction.Request.START.getPreferredName())); request.setEnd(restRequest.param(GetRecordsAction.Request.END.getPreferredName())); - request.setIncludeInterim(restRequest.paramAsBoolean(GetRecordsAction.Request.INCLUDE_INTERIM.getPreferredName(), false)); + request.setExcludeInterim(restRequest.paramAsBoolean(GetRecordsAction.Request.EXCLUDE_INTERIM.getPreferredName(), false)); request.setPageParams(new PageParams(restRequest.paramAsInt(PageParams.FROM.getPreferredName(), PageParams.DEFAULT_FROM), restRequest.paramAsInt(PageParams.SIZE.getPreferredName(), PageParams.DEFAULT_SIZE))); request.setRecordScore( diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/GetBucketActionRequestTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/GetBucketActionRequestTests.java index 9d3ca7eba08..43fe28b9a14 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/GetBucketActionRequestTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/GetBucketActionRequestTests.java @@ -26,7 +26,7 @@ public class GetBucketActionRequestTests extends AbstractStreamableXContentTestC request.setEnd(String.valueOf(randomLong())); } if (randomBoolean()) { - request.setIncludeInterim(randomBoolean()); + request.setExcludeInterim(randomBoolean()); } if (randomBoolean()) { request.setAnomalyScore(randomDouble()); @@ -42,7 +42,7 @@ public class GetBucketActionRequestTests extends AbstractStreamableXContentTestC request.setExpand(randomBoolean()); } if (randomBoolean()) { - request.setIncludeInterim(randomBoolean()); + request.setExcludeInterim(randomBoolean()); } return request; } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/GetInfluencersActionRequestTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/GetInfluencersActionRequestTests.java index 392215039d2..474b39d7538 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/GetInfluencersActionRequestTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/GetInfluencersActionRequestTests.java @@ -32,7 +32,7 @@ public class GetInfluencersActionRequestTests extends AbstractStreamableXContent request.setAnomalyScore(randomDouble()); } if (randomBoolean()) { - request.setIncludeInterim(randomBoolean()); + request.setExcludeInterim(randomBoolean()); } if (randomBoolean()) { request.setSort(randomAlphaOfLengthBetween(1, 20)); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/GetRecordsActionRequestTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/GetRecordsActionRequestTests.java index 2a7ccee8b91..a0665f60d1d 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/GetRecordsActionRequestTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/GetRecordsActionRequestTests.java @@ -38,7 +38,7 @@ public class GetRecordsActionRequestTests extends AbstractStreamableXContentTest request.setRecordScore(randomDouble()); } if (randomBoolean()) { - request.setIncludeInterim(randomBoolean()); + request.setExcludeInterim(randomBoolean()); } if (randomBoolean()) { int from = randomInt(PageParams.MAX_FROM_SIZE_SUM); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/UpdateInterimResultsIT.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/UpdateInterimResultsIT.java index d5061cfdb36..1b8a0254a77 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/UpdateInterimResultsIT.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/UpdateInterimResultsIT.java @@ -123,7 +123,6 @@ public class UpdateInterimResultsIT extends MlNativeAutodetectIntegTestCase { private List getInterimResults(String jobId) throws Exception { GetBucketsAction.Request request = new GetBucketsAction.Request(jobId); - request.setIncludeInterim(true); request.setExpand(true); request.setPageParams(new PageParams(0, 1500)); GetBucketsAction.Response response = client().execute(GetBucketsAction.INSTANCE, request).get(); diff --git a/plugin/src/test/resources/rest-api-spec/api/xpack.ml.get_buckets.json b/plugin/src/test/resources/rest-api-spec/api/xpack.ml.get_buckets.json index 606d078e485..4cb7a1feefe 100644 --- a/plugin/src/test/resources/rest-api-spec/api/xpack.ml.get_buckets.json +++ b/plugin/src/test/resources/rest-api-spec/api/xpack.ml.get_buckets.json @@ -23,9 +23,9 @@ "type": "boolean", "description" : "Include anomaly records" }, - "include_interim": { + "exclude_interim": { "type": "boolean", - "description" : "Include interim results" + "description" : "Exclude interim results" }, "from": { "type": "int", diff --git a/plugin/src/test/resources/rest-api-spec/api/xpack.ml.get_influencers.json b/plugin/src/test/resources/rest-api-spec/api/xpack.ml.get_influencers.json index 4bf6e733588..a1798eca664 100644 --- a/plugin/src/test/resources/rest-api-spec/api/xpack.ml.get_influencers.json +++ b/plugin/src/test/resources/rest-api-spec/api/xpack.ml.get_influencers.json @@ -11,9 +11,9 @@ } }, "params": { - "include_interim": { + "exclude_interim": { "type": "boolean", - "description" : "Include interim results" + "description" : "Exclude interim results" }, "from": { "type": "int", diff --git a/plugin/src/test/resources/rest-api-spec/api/xpack.ml.get_records.json b/plugin/src/test/resources/rest-api-spec/api/xpack.ml.get_records.json index 87bb854cb45..4685d522583 100644 --- a/plugin/src/test/resources/rest-api-spec/api/xpack.ml.get_records.json +++ b/plugin/src/test/resources/rest-api-spec/api/xpack.ml.get_records.json @@ -13,9 +13,9 @@ } }, "params": { - "include_interim": { + "exclude_interim": { "type": "boolean", - "description": "Include interim results" + "description": "Exclude interim results" }, "from": { "type": "int", diff --git a/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_result_buckets.yaml b/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_result_buckets.yaml index ece60ee3046..bb84ba4b97a 100644 --- a/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_result_buckets.yaml +++ b/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_result_buckets.yaml @@ -18,14 +18,27 @@ setup: index: .ml-anomalies-farequote type: result id: "farequote_1464739200000_1" - body: { "job_id": "farequote", "result_type": "bucket", "timestamp": "2016-06-01T00:00:00Z", "bucket_span":1 } + body: + { + "job_id": "farequote", + "result_type": "bucket", + "timestamp": "2016-06-01T00:00:00Z", + "bucket_span":1 + } - do: index: index: .ml-anomalies-farequote type: result id: "farequote_1464739200000_2" - body: { "job_id": "farequote", "result_type": "bucket", "timestamp": "2016-08-01T00:00:00Z", "bucket_span":1 } + body: + { + "job_id": "farequote", + "result_type": "bucket", + "timestamp": "2016-08-01T00:00:00Z", + "bucket_span":1, + "is_interim": true + } - do: indices.refresh: @@ -58,6 +71,26 @@ setup: - match: { buckets.1.job_id: farequote} - match: { buckets.1.result_type: bucket} +--- +"Test get buckets given exclude_interim is false": + - do: + xpack.ml.get_buckets: + job_id: "farequote" + exclude_interim: false + + - match: { count: 2 } + +--- +"Test get buckets given exclude_interim is true": + - do: + xpack.ml.get_buckets: + job_id: "farequote" + exclude_interim: true + + - match: { count: 1 } + - match: { buckets.0.timestamp: 1464739200000 } + - match: { buckets.0.is_interim: false } + --- "Test result single bucket api": - do: diff --git a/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_result_influencers.yaml b/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_result_influencers.yaml index 8fe355d8d8c..1a5447e244b 100644 --- a/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_result_influencers.yaml +++ b/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_result_influencers.yaml @@ -44,7 +44,8 @@ setup: "influencer_score": 50.0, "result_type" : "influencer", "bucket_span" : 1, - "sequence_num" : 2 + "sequence_num" : 2, + "is_interim": true } - do: indices.refresh: @@ -60,6 +61,26 @@ setup: - match: { influencers.0.timestamp: 1464739200000 } - match: { influencers.1.timestamp: 1464825600000 } +--- +"Test get influencers given exclude_interim false": + - do: + xpack.ml.get_influencers: + job_id: "farequote" + exclude_interim: false + + - match: { count: 2 } + +--- +"Test get influencers given exclude_interim true": + - do: + xpack.ml.get_influencers: + job_id: "farequote" + exclude_interim: true + + - match: { count: 1 } + - match: { influencers.0.timestamp: 1464739200000 } + - match: { influencers.0.is_interim: false } + --- "Test result influencers api with time range": - do: diff --git a/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_result_records.yaml b/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_result_records.yaml index 87ba5821c42..38f2acbd649 100644 --- a/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_result_records.yaml +++ b/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_result_records.yaml @@ -40,7 +40,8 @@ setup: "timestamp": "2016-06-02T00:00:00Z", "record_score": 80.0, "bucket_span": 1, - "sequence_num": 2 + "sequence_num": 2, + "is_interim": true } - do: @@ -61,6 +62,26 @@ setup: - match: { records.1.job_id: farequote} - match: { records.1.result_type: record} +--- +"Test get records given exclude_interim is false": + - do: + xpack.ml.get_records: + job_id: "farequote" + exclude_interim: false + + - match: { count: 2 } + +--- +"Test get records given exclude_interim is true": + - do: + xpack.ml.get_records: + job_id: "farequote" + exclude_interim: true + + - match: { count: 1 } + - match: { records.0.timestamp: 1464739200000 } + - match: { records.0.is_interim: false } + --- "Test result records api with time range": - do: