diff --git a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/RunningStats.java b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/RunningStats.java index 1be3279e8ea..15fe158498c 100644 --- a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/RunningStats.java +++ b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/RunningStats.java @@ -82,19 +82,28 @@ public class RunningStats implements Writeable, Cloneable { // read doc count docCount = (Long)in.readGenericValue(); // read fieldSum - fieldSum = (HashMap)in.readGenericValue(); + fieldSum = convertIfNeeded((Map)in.readGenericValue()); // counts - counts = (HashMap)in.readGenericValue(); + counts = convertIfNeeded((Map)in.readGenericValue()); // means - means = (HashMap)in.readGenericValue(); + means = convertIfNeeded((Map)in.readGenericValue()); // variances - variances = (HashMap)in.readGenericValue(); + variances = convertIfNeeded((Map)in.readGenericValue()); // skewness - skewness = (HashMap)in.readGenericValue(); + skewness = convertIfNeeded((Map)in.readGenericValue()); // kurtosis - kurtosis = (HashMap)in.readGenericValue(); + kurtosis = convertIfNeeded((Map)in.readGenericValue()); // read covariances - covariances = (HashMap>)in.readGenericValue(); + covariances = convertIfNeeded((Map>)in.readGenericValue()); + } + + // Convert Map to HashMap if it isn't + private static HashMap convertIfNeeded(Map map) { + if (map instanceof HashMap) { + return (HashMap) map; + } else { + return new HashMap<>(map); + } } @Override diff --git a/server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java b/server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java index d72134198b8..1db66f1d8ad 100644 --- a/server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/InnerHitBuilder.java @@ -365,7 +365,7 @@ public final class InnerHitBuilder implements Writeable, ToXContentObject { * Adds a field to load from the docvalue and return. */ public InnerHitBuilder addDocValueField(String field, String format) { - if (docValueFields == null) { + if (docValueFields == null || docValueFields.isEmpty() == true) { docValueFields = new ArrayList<>(); } docValueFields.add(new FieldAndFormat(field, format));