diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/results/Bucket.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/results/Bucket.java index bb39f56b56d..fcea3f25512 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/results/Bucket.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/results/Bucket.java @@ -162,14 +162,16 @@ public class Bucket extends ToXContentToBytes implements Writeable { builder.field(BUCKET_SPAN.getPreferredName(), bucketSpan); builder.field(INITIAL_ANOMALY_SCORE.getPreferredName(), initialAnomalyScore); builder.field(RECORD_COUNT.getPreferredName(), recordCount); - if (!records.isEmpty()) { + if (records.isEmpty() == false) { builder.field(RECORDS.getPreferredName(), records); } builder.field(EVENT_COUNT.getPreferredName(), eventCount); builder.field(IS_INTERIM.getPreferredName(), isInterim); builder.field(BUCKET_INFLUENCERS.getPreferredName(), bucketInfluencers); builder.field(PROCESSING_TIME_MS.getPreferredName(), processingTimeMs); - builder.field(PARTITION_SCORES.getPreferredName(), partitionScores); + if (partitionScores.isEmpty() == false) { + builder.field(PARTITION_SCORES.getPreferredName(), partitionScores); + } builder.field(Result.RESULT_TYPE.getPreferredName(), RESULT_TYPE_VALUE); builder.endObject(); return builder; 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 bb84ba4b97a..ed9fb23c44a 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 @@ -70,6 +70,8 @@ setup: - match: { buckets.1.timestamp: 1470009600000 } - match: { buckets.1.job_id: farequote} - match: { buckets.1.result_type: bucket} + - is_false: buckets.0.partition_scores + - is_false: buckets.1.partition_scores --- "Test get buckets given exclude_interim is false":