diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java index 3337b6d239413..69b6e311e23ee 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/topmetrics/TopMetricsAggregator.java @@ -40,11 +40,9 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; -import static java.util.stream.Collectors.toList; import static org.elasticsearch.xpack.analytics.topmetrics.TopMetricsAggregationBuilder.REGISTRY_KEY; /** @@ -148,9 +146,14 @@ public void doClose() { static class Metrics implements BucketedSort.ExtraData, Releasable { private final MetricValues[] values; + private final List names; Metrics(MetricValues[] values) { this.values = values; + names = new ArrayList<>(values.length); + for (MetricValues value : values) { + names.add(value.name); + } } boolean needsScores() { @@ -182,7 +185,7 @@ BucketedSort.ResultBuilder resultBuilder(DocValueF } List names() { - return Arrays.stream(values).map(v -> v.name).collect(toList()); + return names; } @Override