diff --git a/plugin/src/main/java/org/opensearch/ml/action/stats/MLStatsNodeResponse.java b/plugin/src/main/java/org/opensearch/ml/action/stats/MLStatsNodeResponse.java index 2904c84172..681e7f15fb 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/stats/MLStatsNodeResponse.java +++ b/plugin/src/main/java/org/opensearch/ml/action/stats/MLStatsNodeResponse.java @@ -33,7 +33,7 @@ public class MLStatsNodeResponse extends BaseNodeResponse implements ToXContentF */ private Map algorithmStats; /** - * Model stats which includes stats level stats. + * Model stats which includes model level stats. * * Example: {model_id: { predict: { request_count: 1} }} */ diff --git a/plugin/src/main/java/org/opensearch/ml/stats/MLModelStats.java b/plugin/src/main/java/org/opensearch/ml/stats/MLModelStats.java index 8c44c309f0..592011938e 100644 --- a/plugin/src/main/java/org/opensearch/ml/stats/MLModelStats.java +++ b/plugin/src/main/java/org/opensearch/ml/stats/MLModelStats.java @@ -36,7 +36,9 @@ public MLModelStats(Map modelStats) { @Override public void writeTo(StreamOutput out) throws IOException { - out.writeMap(modelStats, (stream, v) -> stream.writeEnum(v), (stream, stats) -> stats.writeTo(stream)); + if (modelStats != null && modelStats.size() > 0) { + out.writeMap(modelStats, (stream, v) -> stream.writeEnum(v), (stream, stats) -> stats.writeTo(stream)); + } } @Override