Skip to content

Commit

Permalink
Reuse metric names in TopMetricsAggregator (elastic#116296)
Browse files Browse the repository at this point in the history
This commit shares a unique instance between all InternalTopMetrics instances.
  • Loading branch information
iverase committed Nov 7, 2024
1 parent 8936459 commit 18ef8cc
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -148,9 +146,14 @@ public void doClose() {

static class Metrics implements BucketedSort.ExtraData, Releasable {
private final MetricValues[] values;
private final List<String> names;

Metrics(MetricValues[] values) {
this.values = values;
names = new ArrayList<>(values.length);
for (MetricValues value : values) {
names.add(value.name);
}
}

boolean needsScores() {
Expand Down Expand Up @@ -182,7 +185,7 @@ BucketedSort.ResultBuilder<InternalTopMetrics.TopMetric> resultBuilder(DocValueF
}

List<String> names() {
return Arrays.stream(values).map(v -> v.name).collect(toList());
return names;
}

@Override
Expand Down

0 comments on commit 18ef8cc

Please sign in to comment.