diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedTimingStats.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedTimingStats.java index 775dc9931bc86..4e2d51b2ebacd 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedTimingStats.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedTimingStats.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.xpack.core.ml.job.results.Result; import org.elasticsearch.xpack.core.ml.utils.ToXContentParams; import java.io.IOException; @@ -38,7 +39,7 @@ public class DatafeedTimingStats implements ToXContentObject, Writeable { private static ConstructingObjectParser createParser() { ConstructingObjectParser parser = new ConstructingObjectParser<>( - "datafeed_timing_stats", + TYPE.getPreferredName(), true, args -> { String jobId = (String) args[0]; @@ -128,6 +129,9 @@ public void writeTo(StreamOutput out) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(); + if (params.paramAsBoolean(ToXContentParams.FOR_INTERNAL_STORAGE, false)) { + builder.field(Result.RESULT_TYPE.getPreferredName(), TYPE.getPreferredName()); + } builder.field(JOB_ID.getPreferredName(), jobId); builder.field(SEARCH_COUNT.getPreferredName(), searchCount); builder.field(BUCKET_COUNT.getPreferredName(), bucketCount); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/TimingStats.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/TimingStats.java index b526d614df3ab..a99260e668685 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/TimingStats.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/TimingStats.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.xpack.core.ml.job.config.Job; +import org.elasticsearch.xpack.core.ml.job.results.Result; import org.elasticsearch.xpack.core.ml.utils.ToXContentParams; import java.io.IOException; @@ -195,6 +196,9 @@ public void writeTo(StreamOutput out) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); + if (params.paramAsBoolean(ToXContentParams.FOR_INTERNAL_STORAGE, false)) { + builder.field(Result.RESULT_TYPE.getPreferredName(), TYPE.getPreferredName()); + } builder.field(Job.ID.getPreferredName(), jobId); builder.field(BUCKET_COUNT.getPreferredName(), bucketCount); if (params.paramAsBoolean(ToXContentParams.INCLUDE_CALCULATED_FIELDS, false)) { diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsPersister.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsPersister.java index 1d960c5741836..783706259a17b 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsPersister.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsPersister.java @@ -38,6 +38,7 @@ import org.elasticsearch.xpack.core.ml.job.results.ForecastRequestStats; import org.elasticsearch.xpack.core.ml.job.results.Influencer; import org.elasticsearch.xpack.core.ml.job.results.ModelPlot; +import org.elasticsearch.xpack.core.ml.utils.ToXContentParams; import java.io.IOException; import java.util.Collections; @@ -130,7 +131,11 @@ private void persistBucketInfluencersStandalone(String jobId, List persist(String indexName) { void persist(String indexName, ActionListener listener) { logCall(indexName); - try (XContentBuilder content = toXContentBuilder(object)) { + try (XContentBuilder content = toXContentBuilder(object, params)) { IndexRequest indexRequest = new IndexRequest(indexName).id(id).source(content).setRefreshPolicy(refreshPolicy); executeAsyncWithOrigin(client.threadPool().getThreadContext(), ML_ORIGIN, indexRequest, listener, client::index); } catch (IOException e) { diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsPersisterTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsPersisterTests.java index 02fd3e3bb3466..bf06fcbda42f8 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsPersisterTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsPersisterTests.java @@ -219,6 +219,7 @@ public void testPersistTimingStats() { assertThat(indexRequest.index(), equalTo(".ml-anomalies-.write-foo")); assertThat(indexRequest.id(), equalTo("foo_timing_stats")); Map expectedSourceAsMap = new HashMap<>(); + expectedSourceAsMap.put("result_type", "timing_stats"); expectedSourceAsMap.put("job_id", "foo"); expectedSourceAsMap.put("bucket_count", 7); expectedSourceAsMap.put("minimum_bucket_processing_time_ms", 1.0); @@ -255,6 +256,7 @@ public void testPersistDatafeedTimingStats() { assertThat(indexRequest.id(), equalTo("foo_datafeed_timing_stats")); assertThat(indexRequest.getRefreshPolicy(), equalTo(WriteRequest.RefreshPolicy.IMMEDIATE)); Map expectedSourceAsMap = new HashMap<>(); + expectedSourceAsMap.put("result_type", "datafeed_timing_stats"); expectedSourceAsMap.put("job_id", "foo"); expectedSourceAsMap.put("search_count", 6); expectedSourceAsMap.put("bucket_count", 66);