diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndexSegments.java b/server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndexSegments.java index f772afa94ba41..fe501e41f2d9a 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndexSegments.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndexSegments.java @@ -20,7 +20,7 @@ public class IndexSegments implements Iterable { private final Map indexShards; - IndexSegments(String index, ShardSegments[] shards) { + IndexSegments(String index, List shards) { this.index = index; Map> tmpIndexShards = new HashMap<>(); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java index d0c049c3155e0..340201be57b1a 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java @@ -27,11 +27,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Set; public class IndicesSegmentResponse extends BroadcastResponse { @@ -61,19 +59,16 @@ public Map getIndices() { } Map indicesSegments = new HashMap<>(); - Set indices = new HashSet<>(); + Map> tmpIndicesSegment = new HashMap<>(); for (ShardSegments shard : shards) { - indices.add(shard.getShardRouting().getIndexName()); + List indexSegments = tmpIndicesSegment.computeIfAbsent( + shard.getShardRouting().getIndexName(), + k -> new ArrayList<>() + ); + indexSegments.add(shard); } - - for (String indexName : indices) { - List shards = new ArrayList<>(); - for (ShardSegments shard : this.shards) { - if (shard.getShardRouting().getIndexName().equals(indexName)) { - shards.add(shard); - } - } - indicesSegments.put(indexName, new IndexSegments(indexName, shards.toArray(new ShardSegments[shards.size()]))); + for (Map.Entry> entry : tmpIndicesSegment.entrySet()) { + indicesSegments.put(entry.getKey(), new IndexSegments(entry.getKey(), entry.getValue())); } this.indicesSegments = indicesSegments; return indicesSegments;